package com.injurydetection.www.view;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.byid.android.ByIdActivity;
import com.google.gson.Gson;
import com.injurydetection.www.MyApplication;
import com.injurydetection.www.R;
import com.injurydetection.www.adapter.MainRvAdapter;
import com.injurydetection.www.bean.DataBean;
import com.injurydetection.www.bean.InvokPortBean;
import com.injurydetection.www.bean.MesEventCount;
import com.injurydetection.www.bean.PostBean;
import com.injurydetection.www.bean.PostBean2;
import com.injurydetection.www.bean.PostReceive2;
import com.injurydetection.www.bean.PostResponse;
import com.injurydetection.www.bean.StringBitmapParameter;
import com.injurydetection.www.control.ExamineControl;
import com.injurydetection.www.control.ExamineListControl;
import com.injurydetection.www.greendao.DataBeanDao;
import com.injurydetection.www.receiver.PowerScreenReceiver;
import com.injurydetection.www.util.ByteUtils;
import com.injurydetection.www.util.CmdExample;
import com.injurydetection.www.util.DateUtils;
import com.injurydetection.www.util.MacUtils;
import com.injurydetection.www.util.RootCmd;
import com.injurydetection.www.util.RootGet;
import com.injurydetection.www.util.TemAdd;
import com.injurydetection.www.util.datautil.DataConvert;
import com.injurydetection.www.util.datautil.MakePackage;
import com.injurydetection.www.util.datautil.OnOpenSerialPortListener1;
import com.injurydetection.www.util.datautil.OnOpenSerialPortListener2;
import com.injurydetection.www.util.datautil.OnSerialPortDataListener1;
import com.injurydetection.www.util.datautil.OnSerialPortDataListener2;
import com.injurydetection.www.util.datautil.SerialPortService;
import com.injurydetection.www.util.datautil.SerialPortService1;
import com.injurydetection.www.util.datautil.SerialPortService2;
import com.injurydetection.www.util.fileutil.FileUtils;
import com.injurydetection.www.util.img.ImgUtils;

import com.injurydetection.www.util.network.ApiWrapper;
import com.injurydetection.www.util.network.MyObserver;
import com.injurydetection.www.util.network.RxHelper;
import com.injurydetection.www.util.network.exception.ExceptionHandle;
import com.injurydetection.www.widget.CreateNewDialog;
import com.injurydetection.www.widget.ExportDataDialog;
import com.injurydetection.www.widget.InitPortDialog;
import com.injurydetection.www.widget.JoinCheckDialog;
import com.injurydetection.www.widget.NormalDialog;
import com.injurydetection.www.widget.SaveDataDialog;
import com.ivsign.android.IDCReader.IDCReaderSDK;
import com.kongqw.serialportlibrary.listener.OnOpenSerialPortListener;
import com.kongqw.serialportlibrary.listener.OnSerialPortDataListener;

import org.achartengine.ChartFactory;
import org.achartengine.GraphicalView;
import org.achartengine.chart.PointStyle;
import org.achartengine.model.XYMultipleSeriesDataset;
import org.achartengine.model.XYSeries;
import org.achartengine.renderer.XYMultipleSeriesRenderer;
import org.achartengine.renderer.XYSeriesRenderer;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.CopyOnWriteArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.util.LinkedArrayList;
import jxl.write.DateTime;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import retrofit2.http.POST;

import static java.lang.Thread.sleep;

public class ExamineFragment extends Fragment implements View.OnClickListener {
    private Gson mGson = new Gson();
    private NormalDialog mNormalDialog;
    private String title = "ECG";
    private XYSeries mSeries;
    private XYMultipleSeriesDataset mDataset;
    private GraphicalView mChartECG;
    private XYMultipleSeriesRenderer mRenderer;
    private Timer mTimerECG;
    private TimerTask mTaskECG;
    private Timer mTimerRefresh;
    private TimerTask mTaskRefresh;
    int x = R.layout.fragment_examine;
    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.body_fl)
    FrameLayout bodyFl;
    @BindView(R.id.score_cl)
    ConstraintLayout scoreCl;
    @BindView(R.id.textView)
    TextView textView;
    @BindView(R.id.name_et)
    EditText nameTv;
    @BindView(R.id.eye_rb_1)
    RadioButton eyeRb1;
    @BindView(R.id.eye_rb_2)
    RadioButton eyeRb2;
    @BindView(R.id.eye_rb_3)
    RadioButton eyeRb3;
    @BindView(R.id.eye_rb_4)
    RadioButton eyeRb4;
    @BindView(R.id.eye_rg)
    RadioGroup eyeRg;
    @BindView(R.id.yuyan_rb_1)
    RadioButton yuyanRb1;
    @BindView(R.id.yuyan_rb_2)
    RadioButton yuyanRb2;
    @BindView(R.id.yuyan_rb_3)
    RadioButton yuyanRb3;
    @BindView(R.id.yuyan_rb_4)
    RadioButton yuyanRb4;
    @BindView(R.id.yuyan_rb_5)
    RadioButton yuyanRb5;
    @BindView(R.id.yuyan_rg)
    RadioGroup yuyanRg;
    @BindView(R.id.yundong_rb_1)
    RadioButton yundongRb1;
    @BindView(R.id.yundong_rb_2)
    RadioButton yundongRb2;
    @BindView(R.id.yundong_rb_3)
    RadioButton yundongRb3;
    @BindView(R.id.yundong_rb_4)
    RadioButton yundongRb4;
    @BindView(R.id.yundong_rb_5)
    RadioButton yundongRb5;
    @BindView(R.id.yundong_rb_6)
    RadioButton yundongRb6;
    @BindView(R.id.yundong_rg)
    RadioGroup yundongRg;
    @BindView(R.id.rv)
    RecyclerView rv;
    @BindView(R.id.create_tv)
    TextView createTv;
    @BindView(R.id.xinlv_cl)
    ConstraintLayout xinlvCl;
    @BindView(R.id.xueya_cl)
    ConstraintLayout xueyaCl;
    @BindView(R.id.xueyang_cl)
    ConstraintLayout xueyangCl;
    @BindView(R.id.huxi_cl)
    ConstraintLayout huxiCl;
    @BindView(R.id.tiwen_cl)
    ConstraintLayout tiwenCl;
    @BindView(R.id.imageView11)
    ImageView imageView11;
    @BindView(R.id.imageView13)
    ImageView imageView13;
    @BindView(R.id.youshangzhi_img)
    ImageView youshangzhiImg;
    @BindView(R.id.imageView9)
    ImageView imageView9;
    @BindView(R.id.btn_right_lower_limb)
    ImageView btnRightLowerLimb;
    @BindView(R.id.imageView15)
    ImageView imageView15;
    @BindView(R.id.imageView10)
    ImageView imageView10;
    @BindView(R.id.btn_head_ok)
    ImageView btnHeadOk;
    @BindView(R.id.btn_neck)
    ImageView btnNeck;
    @BindView(R.id.neck_img)
    ImageView neckImg;
    @BindView(R.id.leftupperlimb_img)
    ImageView leftupperlimbImg;
    @BindView(R.id.btn_left_upper_limb)
    ImageView btnLeftUpperLimb;
    @BindView(R.id.imageView14)
    ImageView imageView14;
    @BindView(R.id.btn_abdomen)
    ImageView btnAbdomen;
    @BindView(R.id.imageView16)
    ImageView imageView16;
    @BindView(R.id.btn_left_lower_limb)
    ImageView btnLeftLowerLimb;
    @BindView(R.id.export_tv)
    TextView exportTv;
    @BindView(R.id.save_tv)
    TextView saveTv;
    @BindView(R.id.erjian_tv)
    TextView erjianTv;
    @BindView(R.id.imageView)
    ImageView imageView;
    @BindView(R.id.imageView3)
    ImageView imageView3;
    @BindView(R.id.imageView4)
    ImageView imageView4;
    @BindView(R.id.imageView5)
    ImageView imageView5;
    @BindView(R.id.imageView6)
    ImageView imageView6;
    @BindView(R.id.textView12)
    TextView textView12;
    @BindView(R.id.textView13)
    TextView textView13;
    @BindView(R.id.textView14)
    TextView textView14;
    @BindView(R.id.textView15)
    TextView textView15;
    @BindView(R.id.textView16)
    TextView textView16;
    @BindView(R.id.textView17)
    TextView textView17;
    @BindView(R.id.textView18)
    TextView textView18;
    @BindView(R.id.textView19)
    TextView textView19;
    @BindView(R.id.textView20)
    TextView textView20;
    @BindView(R.id.textView21)
    TextView textView21;
    @BindView(R.id.textView22)
    TextView textView22;
    @BindView(R.id.textView23)
    TextView textView23;
    @BindView(R.id.textView24)
    TextView textView24;
    @BindView(R.id.textView25)
    TextView textView25;
    @BindView(R.id.textView4)
    TextView textView4;
    @BindView(R.id.textView6)
    TextView textView6;
    @BindView(R.id.textView7)
    TextView textView7;
    @BindView(R.id.textView8)
    TextView textView8;
    @BindView(R.id.textView9)
    TextView textView9;
    @BindView(R.id.textView10)
    TextView textView10;
    @BindView(R.id.textView11)
    TextView textView11;
    @BindView(R.id.tiwen_tv)
    TextView tiwenTv;
    @BindView(R.id.xueya_tv)
    TextView xueyaTv;
    @BindView(R.id.editText2)
    EditText editText2;
    @BindView(R.id.head_select)
    ImageView headSelect;
    @BindView(R.id.neck_select)
    ImageView neckSelect;
    @BindView(R.id.rightup_select)
    ImageView rightupSelect;
    @BindView(R.id.leftup_select)
    ImageView leftupSelect;
    @BindView(R.id.chest_select)
    ImageView chestSelect;
    @BindView(R.id.fubu_select)
    ImageView fubuSelect;
    @BindView(R.id.rightlow_select)
    ImageView rightlowSelect;
    @BindView(R.id.leftlow_select)
    ImageView leftlowSelect;
    @BindView(R.id.btn_chest)
    ImageView btnChest;
    @BindView(R.id.btn_right_up)
    ImageView btnRightUp;
    @BindView(R.id.btn_leftup)
    ImageView btnLeftup;
    @BindView(R.id.btn_right_low)
    ImageView btnRightLow;
    @BindView(R.id.btn_left_low)
    ImageView btnLeftLow;
    @BindView(R.id.btn_head_ok1)
    ImageView btnHeadOk1;
    @BindView(R.id.btn_neck1)
    ImageView btnNeck1;
    @BindView(R.id.btn_abdomen1)
    ImageView btnAbdomen1;
    @BindView(R.id.ll_ecg)
    LinearLayout llEcg;
    @BindView(R.id.xuexing)
    TextView xuexing;
    @BindView(R.id.idcard_et)
    EditText idcardEt;
    private String idNum;
    private Unbinder mUnbinder;
    private static final String TAG = "ExamineFragment";
    private LinearLayoutManager mLinearLayoutManager;
    private int eye = 0, yuyan = 0, yundong = 0;
    private boolean xiongbu, youshangzhi, youxiazhi, toubu, jingbu, zuoshangzhi, fubu, zuoxiazhi, beibu;
    private boolean isNew = true;
    private boolean isShow;

    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (isShow) {
                switch (msg.what) {
                    case 0:
                        textView25.setText(wendu);
                        break;
                    case 1:
                        textView14.setText(shousuoya + "");
                        textView16.setText(shuzhangya + "");
                        break;
                    case 2:
                        textView19.setText(xueyang + "");
                        break;
                    case 3:
                        textView22.setText(huxilv + "");
                        textView11.setText(xinlv + "");
                        break;
                    case 4://不使用
//                        updateEcgCure(mBytes);
                        Log.e(TAG, "onDataReceived: hahahaha" + (0xff & mBytes[248]));

                        break;
                    case 10:
                        mInitPortDialog = new InitPortDialog(getContext(), R.style.TipDialog, "系统初始化，请稍等！", false);
                        mInitPortDialog.show();
                        mInitPortDialog.setCancelable(false);
                        mInitPortDialog.getWindow().setLayout(1000, 500);
                        break;
                    case 11:
                        if (mInitPortDialog != null) {
                            mInitPortDialog.setMessage("初始化完成！");
                            mInitPortDialog.setCanceledOnTouchOutside(true);
                        }
                        break;
                    case 12:
                        idcardEt.setText(idNum);
                        break;
                    case 500:
                        Toast.makeText(getContext(), "测量失败！请重新测量！", Toast.LENGTH_LONG).show();
                        break;
                }
            }
        }
    };
    private String wendu;
    private MainRvAdapter mainRvAdapter;
    private PowerScreenReceiver receiver;
    private ExportDataDialog exportDataDialog;
    private InitPortDialog mInitPortDialog;
    private SaveDataDialog saveDataDialog;
    private CountDownTimer timer;

    public ExamineFragment() {
        // Required empty public constructor
    }

    private List<DataBean> mDataBeans;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EventBus.getDefault().register(this);
//        Log.e(TAG, "执行了+++++++++++++++++++++++");
        // 需要使用动态注册才能接收到广播
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
        intentFilter.addAction(Intent.ACTION_SCREEN_ON);
        receiver = new PowerScreenReceiver();
        Objects.requireNonNull(getContext()).registerReceiver(receiver, intentFilter);
        eye = 0;
        yuyan = 0;
        yundong = 0;

    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_examine, container, false);
        mUnbinder = ButterKnife.bind(this, view);
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                //查询数据库所有数据
                mDataBeans = MyApplication.getDaoSession().getDataBeanDao().queryBuilder().where(DataBeanDao.Properties.IsChecked.eq(true)).build().list();
            }
        }, 1000, 2000);

        ExamineControl.setAlphaChange(createTv, xueyaTv, tiwenTv, exportTv, erjianTv, saveTv);

        initRv();

        ExamineListControl.change(getContext(), xuexing, false);


        // Inflate the layout for this fragment
        return view;
    }

    @SuppressLint("HandlerLeak")
    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initListener();

        mSeries = new XYSeries(title);
        mDataset = new XYMultipleSeriesDataset();
        mDataset.addSeries(mSeries);
        int color = Color.parseColor("#9E9AFF");
        PointStyle style = PointStyle.POINT;
        mRenderer = buildRenderer(color, style, false);
        setChartSettings(mRenderer, "X", "Y", 0, 300, -20, 300, Color.WHITE, Color.WHITE);
        //生成图表
        mChartECG = ChartFactory.getLineChartView(getContext(), mDataset, mRenderer);

        llEcg.addView(mChartECG, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));

    }

    protected XYMultipleSeriesRenderer buildRenderer(int color, PointStyle style, boolean fill) {
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();

        //设置图表中曲线本身的样式，包括颜色、点的大小以及线的粗细等
        XYSeriesRenderer r = new XYSeriesRenderer();
        r.setColor(color);
        r.setPointStyle(style);
        r.setFillPoints(fill);
        r.setLineWidth(3);
        renderer.addSeriesRenderer(r);

        return renderer;
    }

    protected void setChartSettings(XYMultipleSeriesRenderer renderer, String xTitle, String yTitle,
                                    double xMin, double xMax, double yMin, double yMax, int axesColor, int labelsColor) {
        //有关对图表的渲染可参看api文档
        //renderer.setChartTitle(title);
        //renderer.setXTitle(xTitle);
        //renderer.setYTitle(yTitle);
        renderer.setXAxisMin(xMin);
        renderer.setXAxisMax(xMax);
        renderer.setYAxisMin(yMin);
        renderer.setShowGrid(true);
        renderer.setYAxisMax(yMax);
        renderer.setAxesColor(Color.BLUE);
        renderer.setShowAxes(false);
        renderer.setShowLabels(false);
        renderer.setShowGrid(false);
        renderer.setShowCustomTextGrid(false);
        renderer.setGridColor(Color.BLUE);
        //renderer.setXLabels(20);
        //renderer.setYLabels(10);
        //renderer.setXTitle("Time");
        //renderer.setYTitle("dBm");
        renderer.setChartTitleTextSize(0);
        renderer.setYLabelsAlign(Paint.Align.RIGHT);
        renderer.setPointSize((float) 2);
        renderer.setShowLegend(false);
        renderer.setMargins(new int[]{0, 0, 0, 0});//设置空白区大小
        renderer.setMarginsColor(Color.BLUE);//设置空白区颜色
        renderer.setZoomEnabled(false, false);// 设置缩放,这边是横向可以缩放,竖向不能缩放
        renderer.setPanEnabled(false, false);// 设置滑动,这边是横向可以滑动,竖向不可滑动
    }

    private int mECGDataIndex = 0;
    int[] mECGBackX = new int[300];//测试
    int[] mECGBackY = new int[300];
    private Handler mHandlerECG;
    private Handler mHandlerRefresh;

    private void updateEcgCure() {

        //设置好下一个需要增加的节点
        mECGX = 0;
        //addY = (int)(Math.random() * 90);
        mECGY = (int) ((mBytes[mECGDataIndex]));
        mECGDataIndex += 4;


        //移除数据集中旧的点集
        mDataset.removeSeries(mSeries);

        //判断当前点集中到底有多少点，因为屏幕总共只能容纳100个，所以当点数超过100时，长度永远是100
        int length = mSeries.getItemCount();
        if (length > 300) {
            length = 300;
        }

        //将旧的点集中x和y的数值取出来放入backup中，并且将x的值加1，造成曲线向右平移的效果
        for (int i = 0; i < length; i++) {
            mECGBackX[i] = (int) mSeries.getX(i) + 1;
            mECGBackY[i] = (int) mSeries.getY(i);
        }

        //点集先清空，为了做成新的点集而准备
        mSeries.clear();

        //将新产生的点首先加入到点集中，然后在循环体中将坐标变换后的一系列点都重新加入到点集中
        //这里可以试验一下把顺序颠倒过来是什么效果，即先运行循环体，再添加新产生的点
        mSeries.add(mECGX, mECGY);
        for (int k = 0; k < length; k++) {
            mSeries.add(mECGBackX[k], mECGBackY[k]);
        }

        //在数据集中添加新的点集
        mDataset.addSeries(mSeries);

        //视图更新，没有这一步，曲线不会呈现动态
        //如果在非UI主线程中，需要调用postInvalidate()，具体参考api
        mChartECG.invalidate();
        if (mECGDataIndex >= mBytes.length) {
            mECGDataIndex = 0;
        }
    }

    private void initListener() {
        textView.setOnClickListener(this);//
        xuexing.setOnClickListener(this);
        createTv.setOnClickListener(this);
        imageView11.setOnClickListener(this);
        imageView9.setOnClickListener(this);
        btnRightLowerLimb.setOnClickListener(this);
        btnBack.setOnClickListener(this);
        btnHeadOk.setOnClickListener(this);
        btnNeck.setOnClickListener(this);
        btnLeftUpperLimb.setOnClickListener(this);
        btnAbdomen.setOnClickListener(this);
        btnLeftLowerLimb.setOnClickListener(this);
        exportTv.setOnClickListener(this);
        saveTv.setOnClickListener(this);
        erjianTv.setOnClickListener(this);
        tiwenTv.setOnClickListener(this);
        xueyaTv.setOnClickListener(this);
        btnChest.setOnClickListener(this);
        btnRightUp.setOnClickListener(this);
        btnLeftup.setOnClickListener(this);
        btnRightLow.setOnClickListener(this);
        btnLeftLow.setOnClickListener(this);
        btnHeadOk1.setOnClickListener(this);
        btnNeck1.setOnClickListener(this);
        btnAbdomen1.setOnClickListener(this);
        eyeRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.eye_rb_1:
                        eye = 1;
                        eyeRb1.setText("不睁眼" +
                                "\u3000\u3000\u3000\u3000\u3000" +
                                "\u3000\u3000\u3000" + "1");
                        eyeRb2.setText("刺痛睁眼");
                        eyeRb3.setText("呼吸睁眼");
                        eyeRb4.setText("自动睁眼");
                        break;
                    case R.id.eye_rb_2:
                        eye = 2;
                        eyeRb2.setText("刺痛睁眼" +
                                "\u3000\u3000\u3000\u3000\u3000" +
                                "\u3000\u3000" + "2");
                        eyeRb1.setText("不睁眼");
                        eyeRb3.setText("呼吸睁眼");
                        eyeRb4.setText("自动睁眼");
                        break;
                    case R.id.eye_rb_3:
                        eye = 3;
                        eyeRb3.setText("呼吸睁眼" +
                                "\u3000\u3000\u3000\u3000\u3000" +
                                "\u3000\u3000" + "3");
                        eyeRb1.setText("不睁眼");
                        eyeRb2.setText("刺痛睁眼");
                        eyeRb4.setText("自动睁眼");
                        break;
                    case R.id.eye_rb_4:
                        eye = 4;
                        eyeRb4.setText("自动睁眼" +
                                "\u3000\u3000\u3000\u3000\u3000" +
                                "\u3000\u3000" + "4");
                        eyeRb1.setText("不睁眼");
                        eyeRb2.setText("刺痛睁眼");
                        eyeRb3.setText("呼吸睁眼");
                        break;
                }
            }
        });
        yuyanRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.yuyan_rb_1:
                        yuyan = 1;
                        yuyanRb1.setText("不能言语" +
                                "\u3000\u3000\u3000\u3000\u3000" +
                                "\u3000\u3000" + "1");
                        yuyanRb2.setText("只能发言");
                        yuyanRb3.setText("答非所问");
                        yuyanRb4.setText("回答不切题");
                        yuyanRb5.setText("回答切题");
                        break;
                    case R.id.yuyan_rb_2:
                        yuyan = 2;
                        yuyanRb1.setText("不能言语");
                        yuyanRb2.setText("只能发言" +
                                "\u3000\u3000\u3000\u3000\u3000" +
                                "\u3000\u3000" + "2");
                        yuyanRb3.setText("答非所问");
                        yuyanRb4.setText("回答不切题");
                        yuyanRb5.setText("回答切题");
                        break;
                    case R.id.yuyan_rb_3:
                        yuyan = 3;
                        yuyanRb1.setText("不能言语");
                        yuyanRb2.setText("只能发言");
                        yuyanRb3.setText("答非所问" +
                                "\u3000\u3000\u3000\u3000\u3000" +
                                "\u3000\u3000" + "3");
                        yuyanRb4.setText("回答不切题");
                        yuyanRb5.setText("回答切题");
                        break;
                    case R.id.yuyan_rb_4:
                        yuyan = 4;
                        yuyanRb1.setText("不能言语");
                        yuyanRb2.setText("只能发言");
                        yuyanRb3.setText("答非所问");
                        yuyanRb4.setText("回答不切题" +
                                "\u3000\u3000\u3000\u3000\u3000" +
                                "\u3000" + "4");
                        yuyanRb5.setText("回答切题");
                        break;
                    case R.id.yuyan_rb_5:
                        yuyan = 5;
                        yuyanRb1.setText("不能言语");
                        yuyanRb2.setText("只能发言");
                        yuyanRb3.setText("答非所问");
                        yuyanRb4.setText("回答不切题");
                        yuyanRb5.setText("回答切题" +
                                "\u3000\u3000\u3000\u3000\u3000" +
                                "\u3000\u3000" + "5");
                        break;
                }
            }
        });
        yundongRg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.yundong_rb_1:
                        yundong = 1;
                        yundongRb1.setText("不能活动" +
                                "\u3000\u3000\u3000\u3000\u3000" +
                                "\u3000\u3000" + "1");
                        yundongRb2.setText("刺痛后肢体能过度伸展");
                        yundongRb3.setText("刺痛后肢体能屈曲");
                        yundongRb4.setText("刺痛后能躲避");
                        yundongRb5.setText("刺痛能定位");
                        yundongRb6.setText("按吩咐动作");
                        break;
                    case R.id.yundong_rb_2:
                        yundong = 2;
                        yundongRb1.setText("不能活动");
                        yundongRb2.setText("刺痛后肢体能过度伸展" +
                                "\u3000" + "2");
                        yundongRb3.setText("刺痛后肢体能屈曲");
                        yundongRb4.setText("刺痛后能躲避");
                        yundongRb5.setText("刺痛能定位");
                        yundongRb6.setText("按吩咐动作");
                        break;
                    case R.id.yundong_rb_3:
                        yundong = 3;
                        yundongRb1.setText("不能活动");
                        yundongRb2.setText("刺痛后肢体能过度伸展");
                        yundongRb3.setText("刺痛后肢体能屈曲" +
                                "\u3000\u3000\u3000" + "3");
                        yundongRb4.setText("刺痛后能躲避");
                        yundongRb5.setText("刺痛能定位");
                        yundongRb6.setText("按吩咐动作");
                        break;
                    case R.id.yundong_rb_4:
                        yundong = 4;
                        yundongRb1.setText("不能活动");
                        yundongRb2.setText("刺痛后肢体能过度伸展");
                        yundongRb3.setText("刺痛后肢体能屈曲");
                        yundongRb4.setText("刺痛后能躲避" +
                                "\u3000\u3000\u3000\u3000\u3000" + "4");
                        yundongRb5.setText("刺痛能定位");
                        yundongRb6.setText("按吩咐动作");
                        break;
                    case R.id.yundong_rb_5:
                        yundong = 5;
                        yundongRb1.setText("不能活动");
                        yundongRb2.setText("刺痛后肢体能过度伸展");
                        yundongRb3.setText("刺痛后肢体能屈曲");
                        yundongRb4.setText("刺痛后能躲避");
                        yundongRb5.setText("刺痛能定位" +
                                "\u3000\u3000\u3000\u3000\u3000\u3000" + "5");
                        yundongRb6.setText("按吩咐动作");
                        break;
                    case R.id.yundong_rb_6:
                        yundong = 6;
                        yundongRb1.setText("不能活动");
                        yundongRb2.setText("刺痛后肢体能过度伸展");
                        yundongRb3.setText("刺痛后肢体能屈曲");
                        yundongRb4.setText("刺痛后能躲避");
                        yundongRb5.setText("刺痛能定位");
                        yundongRb6.setText("按吩咐动作" +
                                "\u3000\u3000\u3000\u3000\u3000\u3000" + "6");
                        break;
                }
            }
        });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mUnbinder.unbind();
        EventBus.getDefault().unregister(this);
        if (mSerialPortService1 != null) {
            mSerialPortService1.closeSerialPort();
        }
        if (mSerialPortService != null) {
            mSerialPortService.closeSerialPort();
        }

        if (mSerialPortService2 != null) {
            mSerialPortService2.closeSerialPort();
        }

        if (receiver != null) {
            getContext().unregisterReceiver(receiver);
        }

    }

    @Override
    public void onPause() {
        super.onPause();
        scoreCl.setVisibility(View.INVISIBLE);
        if (timer != null) {
            timer.cancel();
        }
        eye = 0;
        yuyan = 0;
        yundong = 0;
        isShow = false;
        isRead = false;
        mTimerECG.cancel();
        mTimerRefresh.cancel();
//        ecgChart.onPause();
        if (mSerialPortService1 != null) {
            mSerialPortService1.closeSerialPort();
        }
        if (mSerialPortService != null) {
            mSerialPortService.closeSerialPort();
        }

        if (mSerialPortService2 != null) {
            mSerialPortService2.closeSerialPort();
        }
    }

    @Override
    public void onStart() {
        super.onStart();
        eye = 0;
        yuyan = 0;
        yundong = 0;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        eye = 0;
        yuyan = 0;
        yundong = 0;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        eye = 0;
        yuyan = 0;
        yundong = 0;
    }


    @SuppressLint("HandlerLeak")
    @Override
    public void onResume() {
        super.onResume();

        /**
         * CountDownTimer timer = new CountDownTimer(3000, 1000)中，
         * 第一个参数表示总时间，第二个参数表示间隔时间。
         * 意思就是每隔一秒会回调一次方法onTick，然后1秒之后会回调onFinish方法。
         * 保存后savedatadialog倒计时3秒消失
         */
         timer = new CountDownTimer(3000, 1000) {
            public void onTick(long millisUntilFinished) {
            }

            public void onFinish() {
                if (saveDataDialog.isShowing()) {
                    saveDataDialog.dismiss();
                }
            }
        };


        initSerialPort();
        initSerialPort1("");
        initSerialPort2();
        isRead = true;
        isShow = true;
        clearData();
        //这里的Handler实例将配合下面的Timer实例，完成定时更新图表的功能
        mHandlerECG = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                //刷新ECG图
                updateEcgCure();
                super.handleMessage(msg);
            }
        };

        mHandlerRefresh = new Handler() {
            @Override
            public void handleMessage(@NonNull Message msg) {
                mDataBeans = MyApplication.getDaoSession().getDataBeanDao().queryBuilder()
                        .where(DataBeanDao.Properties.IsChecked.eq(true))
                        .orderAsc(DataBeanDao.Properties.CreateTime)
                        .build().list();

                List<DataBean> list = new ArrayList<>();
                if (mDataBeans.size() > 0) {
                    for (int i1 = 0; i1 < mDataBeans.size(); i1++) {
                        if ((new Date().getTime() - mDataBeans.get(i1).getCreateTime().getTime()) / 1000 / 60 / 60 <= 5) {
                            list.add(mDataBeans.get(i1));
                        }
                    }
                }

                mainRvAdapter.setDataBeans(list);
                mainRvAdapter.notifyDataSetChanged();
                super.handleMessage(msg);
            }
        };
        mTaskECG = new TimerTask() {
            @Override
            public void run() {
                Message message = new Message();
                message.what = 1;
                mHandlerECG.sendMessage(message);
            }
        };
        mTaskRefresh = new TimerTask() {
            @Override
            public void run() {
                Message message = new Message();
                message.what = 1;
                mHandlerRefresh.sendMessage(message);
            }
        };
        mTimerECG = new Timer();
        mTimerRefresh = new Timer();
        mTimerECG.schedule(mTaskECG, 100, 40);
        mTimerRefresh.schedule(mTaskRefresh, 3000, 1000 * 60);


        TextView gaoyatest = (TextView) getView().findViewById(R.id.textView14);
        gaoyatest.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
//                Log.e(TAG, "afterTextChanged: textView14" + eye);
                if (!textView14.getText().toString().equals("-") && !textView22.getText().toString().equals("--") && eye > 0 && yuyan > 0 && yundong > 0) {
                    scoreCl.setVisibility(View.VISIBLE);

                    int shousuoyaLevel = 0;
                    if (!textView14.getText().toString().equals("-")) {
                        if (Integer.parseInt(textView14.getText().toString()) > 89) {
                            shousuoyaLevel = 4;
                        } else if (Integer.parseInt(textView14.getText().toString()) <= 89 && Integer.parseInt(textView14.getText().toString()) >= 76) {
                            shousuoyaLevel = 3;
                        } else if (Integer.parseInt(textView14.getText().toString()) <= 75 && Integer.parseInt(textView14.getText().toString()) >= 50) {
                            shousuoyaLevel = 2;
                        } else if (Integer.parseInt(textView14.getText().toString()) >= 1 && Integer.parseInt(textView14.getText().toString()) <= 49) {
                            shousuoyaLevel = 1;
                        }
                    }

                    int huxilv = 0;
                    if (!textView22.getText().toString().equals("--")) {
                        if (Integer.parseInt(textView22.getText().toString()) > 29) {
                            huxilv = 3;
                        } else if (Integer.parseInt(textView22.getText().toString()) >= 10 && Integer.parseInt(textView22.getText().toString()) <= 29) {
                            huxilv = 4;
                        } else if (Integer.parseInt(textView22.getText().toString()) >= 6 && Integer.parseInt(textView22.getText().toString()) <= 9) {
                            huxilv = 2;
                        } else if (Integer.parseInt(textView22.getText().toString()) >= 4 && Integer.parseInt(textView22.getText().toString()) <= 5) {
                            huxilv = 1;
                        }
                    }

                    int shenzhipanduan = 0;
                    int shenzhi = eye + yuyan + yundong;
                    if (shenzhi >= 13 && shenzhi <= 15) {
                        shenzhipanduan = 4;
                    } else if (shenzhi >= 9 && shenzhi <= 12) {
                        shenzhipanduan = 3;
                    } else if (shenzhi >= 6 && shenzhi <= 8) {
                        shenzhipanduan = 2;
                    } else if (shenzhi >= 4 && shenzhi <= 5) {
                        shenzhipanduan = 1;
                    }

                    int shangqingLevel = shenzhipanduan + huxilv + shousuoyaLevel;
                    textView4.setText(shangqingLevel + "");
                    textView6.setText("分");
                    if (shangqingLevel >= 12) {
                        textView8.setText("轻伤");
                        textView7.setText("常规处置");
                        textView4.setTextColor(Color.GREEN);
                        textView6.setTextColor(Color.GREEN);
                        textView8.setTextColor(Color.GREEN);
                        textView7.setTextColor(Color.GREEN);
                        scoreCl.setBackgroundColor(Color.parseColor("#222127"));
                    } else if (shangqingLevel >= 10) {
                        textView8.setText("中度伤");
                        textView7.setText("优先处置");
                        textView4.setTextColor(Color.YELLOW);
                        textView6.setTextColor(Color.YELLOW);
                        textView8.setTextColor(Color.YELLOW);
                        textView7.setTextColor(Color.YELLOW);
                        scoreCl.setBackgroundColor(Color.parseColor("#222127"));
                    } else if (shangqingLevel >= 6) {
                        textView8.setText("重伤");
                        textView7.setText("紧急处置");
                        textView4.setTextColor(Color.RED);
                        textView6.setTextColor(Color.RED);
                        textView8.setTextColor(Color.RED);
                        textView7.setTextColor(Color.RED);
                        scoreCl.setBackgroundColor(Color.parseColor("#222127"));
                    } else {
                        textView8.setText("危重伤");
                        textView7.setText("期待处置");
                        textView4.setTextColor(Color.BLACK);
                        textView6.setTextColor(Color.BLACK);
                        textView8.setTextColor(Color.BLACK);
                        textView7.setTextColor(Color.BLACK);
                        scoreCl.setBackgroundColor(Color.RED);
                    }
                }
            }
        });

        TextView huxitest = (TextView) getView().findViewById(R.id.textView22);
        eye = 0;
        yuyan = 0;
        yundong = 0;
        huxitest.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
//                Log.e(TAG, "afterTextChanged: textView22" + eye);

                if (!textView14.getText().toString().equals("-") && !textView22.getText().toString().equals("--") && eye > 0 && yuyan > 0 && yundong > 0) {
                    scoreCl.setVisibility(View.VISIBLE);
                    int shousuoyaLevel = 0;
                    if (!textView14.getText().toString().equals("-")) {
                        if (Integer.parseInt(textView14.getText().toString()) > 89) {
                            shousuoyaLevel = 4;
                        } else if (Integer.parseInt(textView14.getText().toString()) <= 89 && Integer.parseInt(textView14.getText().toString()) >= 76) {
                            shousuoyaLevel = 3;
                        } else if (Integer.parseInt(textView14.getText().toString()) <= 75 && Integer.parseInt(textView14.getText().toString()) >= 50) {
                            shousuoyaLevel = 2;
                        } else if (Integer.parseInt(textView14.getText().toString()) >= 1 && Integer.parseInt(textView14.getText().toString()) <= 49) {
                            shousuoyaLevel = 1;
                        }
                    }

                    int huxilv = 0;
                    if (!textView22.getText().toString().equals("--")) {
                        if (Integer.parseInt(textView22.getText().toString()) > 29) {
                            huxilv = 3;
                        } else if (Integer.parseInt(textView22.getText().toString()) >= 10 && Integer.parseInt(textView22.getText().toString()) <= 29) {
                            huxilv = 4;
                        } else if (Integer.parseInt(textView22.getText().toString()) >= 6 && Integer.parseInt(textView22.getText().toString()) <= 9) {
                            huxilv = 2;
                        } else if (Integer.parseInt(textView22.getText().toString()) >= 4 && Integer.parseInt(textView22.getText().toString()) <= 5) {
                            huxilv = 1;
                        }
                    }

                    int shenzhipanduan = 0;
                    int shenzhi = eye + yuyan + yundong;
                    if (shenzhi >= 13 && shenzhi <= 15) {
                        shenzhipanduan = 4;
                    } else if (shenzhi >= 9 && shenzhi <= 12) {
                        shenzhipanduan = 3;
                    } else if (shenzhi >= 6 && shenzhi <= 8) {
                        shenzhipanduan = 2;
                    } else if (shenzhi >= 4 && shenzhi <= 5) {
                        shenzhipanduan = 1;
                    }

                    int shangqingLevel = shenzhipanduan + huxilv + shousuoyaLevel;
                    textView4.setText(shangqingLevel + "");
                    textView6.setText("分");

                    if (shangqingLevel >= 12) {
                        textView8.setText("轻伤");
                        textView7.setText("常规处置");
                        textView4.setTextColor(Color.GREEN);
                        textView6.setTextColor(Color.GREEN);
                        textView8.setTextColor(Color.GREEN);
                        textView7.setTextColor(Color.GREEN);
                        scoreCl.setBackgroundColor(Color.parseColor("#222127"));
                    } else if (shangqingLevel >= 10) {
                        textView8.setText("中度伤");
                        textView7.setText("优先处置");
                        textView4.setTextColor(Color.YELLOW);
                        textView6.setTextColor(Color.YELLOW);
                        textView8.setTextColor(Color.YELLOW);
                        textView7.setTextColor(Color.YELLOW);
                        scoreCl.setBackgroundColor(Color.parseColor("#222127"));
                    } else if (shangqingLevel >= 6) {
                        textView8.setText("重伤");
                        textView7.setText("紧急处置");
                        textView4.setTextColor(Color.RED);
                        textView6.setTextColor(Color.RED);
                        textView8.setTextColor(Color.RED);
                        textView7.setTextColor(Color.RED);
                        scoreCl.setBackgroundColor(Color.parseColor("#222127"));
                    } else {
                        textView8.setText("危重伤");
                        textView7.setText("期待处置");
                        textView4.setTextColor(Color.BLACK);
                        textView6.setTextColor(Color.BLACK);
                        textView8.setTextColor(Color.BLACK);
                        textView7.setTextColor(Color.BLACK);
                        scoreCl.setBackgroundColor(Color.RED);
                    }
                }
            }
        });

    }

    private void initRv() {
        mLinearLayoutManager = new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false);
        rv.setLayoutManager(mLinearLayoutManager);

        mDataBeans = MyApplication.getDaoSession().getDataBeanDao().queryBuilder()
                .where(DataBeanDao.Properties.IsChecked.eq(true))
                .orderAsc(DataBeanDao.Properties.CreateTime)
                .build().list();

        List<DataBean> list = new ArrayList<>();
        if (mDataBeans.size() > 0) {
            for (int i1 = 0; i1 < mDataBeans.size(); i1++) {
                if ((new Date().getTime() - mDataBeans.get(i1).getCreateTime().getTime()) / (1000 * 60 * 60) <= 5) {
                    list.add(mDataBeans.get(i1));
                }
            }
        }

        mainRvAdapter = new MainRvAdapter(list, getContext());

        mainRvAdapter.setClickListener(new MainRvAdapter.ClickListener() {
            @Override
            public void onItemClick(List<DataBean> dataBeans, int positon) {
                isNew = true;
                clearData();
                nameTv.setText(dataBeans.get(positon).getName());
                editText2.setText(dataBeans.get(positon).getNumber());
                xuexing.setText(dataBeans.get(positon).getBloodType());
                xuexingStr = xuexing.getText().toString();
            }
        });
        rv.setAdapter(mainRvAdapter);
        mainRvAdapter.notifyDataSetChanged();
    }

    private String xuexingStr = "血型";

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.textView:
//                mSerialPortService2.sendBytes(MakePackage.cmd_find);
                break;
            case R.id.xuexing:
                ExamineListControl.showPopu(getContext(), xuexing, R.menu.item_xuexing1, new ExamineListControl.ItemSelect() {
                    @Override
                    public void onItemSelect(MenuItem item) {
                        xuexingStr = item.getTitle().toString();
                    }
                });
                break;
            case R.id.create_tv:
                isNew = true;
                CreateNewDialog dialog = new CreateNewDialog(getContext(), R.style.TipDialog);
                dialog.setCommitListener(new CreateNewDialog.CommitListener() {
                    @Override
                    public void commit() {
                        clearData();
                    }
                });
                dialog.show();
                dialog.getWindow().setLayout(1000, 500);
                break;
            case R.id.btn_chest:
                changeBody(0);
                break;
            case R.id.btn_right_up://右上肢
                changeBody(1);
                break;
            case R.id.btn_right_low:
                changeBody(2);
                break;
            case R.id.btn_head_ok1:
                changeBody(3);
                break;
            case R.id.btn_neck1:
                changeBody(4);
                break;
            case R.id.btn_leftup:
                changeBody(5);
                break;
            case R.id.btn_abdomen1:
                changeBody(6);
                break;
            case R.id.btn_left_low:
                changeBody(7);
                break;
            case R.id.btn_back:
                changeBody(8);
                break;
            case R.id.export_tv:// || xuexing.getText().toString().equals("全部") || xuexing.getText().toString().equals("血型")
                if (nameTv.getText().toString().isEmpty() || editText2.getText().toString().isEmpty()) {
//                    Toast.makeText(getContext(), "请输入个人信息", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请输入个人信息！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (TextUtils.isEmpty(textView4.getText().toString()) || eye == 0 || yuyan == 0 || yundong == 0) {
//                    Toast.makeText(getContext(), "请先补充检伤信息！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请先补充检伤信息！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (textView19.getText().toString().equals("--")) {
//                    Toast.makeText(getContext(), "请测量血氧！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量血氧！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (textView22.getText().toString().equals("--")) {
//                    Toast.makeText(getContext(), "请测量呼吸率！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量呼吸率！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (textView25.getText().toString().equals("--")) {
//                    Toast.makeText(getContext(), "请测量体温！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量体温！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }

                if (TextUtils.isEmpty(textView4.getText().toString())) {
//                    Toast.makeText(getContext(), "请先补充检伤信息！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请先补充检伤信息！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }


//                ExcelUtils.writeObjListToExcel(mPersonList, Environment.getExternalStorageDirectory().getAbsolutePath() + "/Download/test.xlsx", getContext());
                exportDataDialog = new ExportDataDialog(getContext(), R.style.TipDialog, "导出中，请稍等！", false);
                exportDataDialog.show();
                exportDataDialog.setCancelable(false);
                exportDataDialog.getWindow().setLayout(1000, 500);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            //保存身体热点图
                            FileUtils.saveFile(ImgUtils.captureView(bodyFl), "test.jpeg", "");
                            sleep(2000);
                            ImageTask imageTask = new ImageTask();
                            imageTask.execute("");
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                }).start();
                break;
            case R.id.save_tv:
                if (editText2.getText().toString().length() != 6) {
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "手环号为6位！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (idcardEt.getText().toString().length() > 0) {
                    if (idcardEt.getText().toString().length() != 18) {
                        mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "身份证编号为18位！");
                        mNormalDialog.show();
                        mNormalDialog.getWindow().setLayout(1000, 500);
                        return;
                    }
                }

                //|| xuexing.getText().toString().equals("全部") || xuexing.getText().toString().equals("血型")
                if (editText2.getText().toString().isEmpty()) {
//                    Toast.makeText(getContext(), "请输入个人信息", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请输入个人信息！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (TextUtils.isEmpty(textView4.getText().toString()) || eye == 0 || yuyan == 0 || yundong == 0) {
//                    Toast.makeText(getContext(), "请先补充检伤信息！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请先补充检伤信息！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }

                if (textView19.getText().toString().equals("--")) {
//                    Toast.makeText(getContext(), "请测量血氧！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量血氧！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (textView22.getText().toString().equals("--")) {
//                    Toast.makeText(getContext(), "请测量呼吸率！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量呼吸率！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (textView25.getText().toString().equals("--")) {
//                    Toast.makeText(getContext(), "请测量体温！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量体温！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (isNew) {//如果是新建，插入新数据
                    String number = editText2.getText().toString().trim().replace(" ", "");
                    //判断数据库中是否有该number和name，同时存在则更新，否则新增
                    List<DataBean> list = MyApplication.getDaoSession().getDataBeanDao().queryBuilder()
                            .where(DataBeanDao.Properties.Number.eq(number))
                            .list();
                    if (list.size() > 0) {
                        //覆盖操作
                        DataBean dataBean = new DataBean();
                        Date date = new Date();
                        dataBean.setNumber(editText2.getText().toString().replace(" ", ""));
                        dataBean.setName(nameTv.getText().toString());
                        int shousuoyaLevel = 0;

                        if (!textView14.getText().toString().equals("-")) {
                            if (Integer.parseInt(textView14.getText().toString()) > 89) {
                                shousuoyaLevel = 4;
                            } else if (Integer.parseInt(textView14.getText().toString()) <= 89 && Integer.parseInt(textView14.getText().toString()) >= 76) {
                                shousuoyaLevel = 3;
                            } else if (Integer.parseInt(textView14.getText().toString()) <= 75 && Integer.parseInt(textView14.getText().toString()) >= 50) {
                                shousuoyaLevel = 2;
                            } else if (Integer.parseInt(textView14.getText().toString()) >= 1 && Integer.parseInt(textView14.getText().toString()) <= 49) {
                                shousuoyaLevel = 1;
                            }
                        } else {
//                            Toast.makeText(getContext(), "请测量血压", Toast.LENGTH_LONG).show();
                            mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量血压！");
                            mNormalDialog.show();
                            mNormalDialog.getWindow().setLayout(1000, 500);
                            return;
                        }

                        int huxilv = 0;
                        if (!textView22.getText().toString().equals("--")) {
                            if (Integer.parseInt(textView22.getText().toString()) > 29) {
                                huxilv = 3;
                            } else if (Integer.parseInt(textView22.getText().toString()) >= 10 && Integer.parseInt(textView22.getText().toString()) <= 29) {
                                huxilv = 4;
                            } else if (Integer.parseInt(textView22.getText().toString()) >= 6 && Integer.parseInt(textView22.getText().toString()) <= 9) {
                                huxilv = 2;
                            } else if (Integer.parseInt(textView22.getText().toString()) >= 4 && Integer.parseInt(textView22.getText().toString()) <= 5) {
                                huxilv = 1;
                            }
                        } else {
//                            Toast.makeText(getContext(), "请测量呼吸率", Toast.LENGTH_LONG).show();
                            mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量呼吸率！");
                            mNormalDialog.show();
                            mNormalDialog.getWindow().setLayout(1000, 500);
                        }

                        int shenzhipanduan = 0;
                        int shenzhi = eye + yuyan + yundong;
                        if (shenzhi >= 13 && shenzhi <= 15) {
                            shenzhipanduan = 4;
                        } else if (shenzhi >= 9 && shenzhi <= 12) {
                            shenzhipanduan = 3;
                        } else if (shenzhi >= 6 && shenzhi <= 8) {
                            shenzhipanduan = 2;
                        } else if (shenzhi >= 4 && shenzhi <= 5) {
                            shenzhipanduan = 1;
                        }

                        int shangqingLevel = shenzhipanduan + huxilv + shousuoyaLevel;
                        if (shangqingLevel == 12) {
                            dataBean.setScoreLevel(1);
                        } else if (shangqingLevel >= 10) {
                            dataBean.setScoreLevel(2);
                        } else if (shangqingLevel >= 6) {
                            dataBean.setScoreLevel(3);
                        } else {
                            dataBean.setScoreLevel(4);
                        }
                        dataBean.setScore(shangqingLevel);
                        dataBean.setBloodType(xuexingStr);
                        dataBean.setBloodPressureH(Integer.parseInt(textView14.getText().toString()));
                        dataBean.setBloodPressureL(Integer.parseInt(textView16.getText().toString()));
                        dataBean.setBloodOxygen(Integer.parseInt(textView19.getText().toString()));
                        dataBean.setTemperature(Float.parseFloat(textView25.getText().toString()));
                        dataBean.setChest(xiongbu);
                        dataBean.setRightUpperLimb(youshangzhi);
                        dataBean.setRightLowLimb(youxiazhi);
                        dataBean.setHead(toubu);
                        dataBean.setNeck(jingbu);
                        dataBean.setLeftUpperLimb(zuoshangzhi);
                        dataBean.setAbdomen(fubu);
                        dataBean.setLeftLowLimb(zuoxiazhi);
                        dataBean.setEye(eye);
                        dataBean.setSay(yuyan);
                        dataBean.setSport(yundong);
                        dataBean.setRespiratoryRate(Integer.parseInt(textView22.getText().toString()));
                        dataBean.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                        dataBean.setCreateTime(date);

                        DataBean dataBeanOld = new DataBean();
                        if (list.size() > 0) {
                            dataBeanOld = list.get(0);
                        }
                        dataBean.setId(dataBeanOld.getId());
                        MyApplication.getDaoSession().getDataBeanDao().update(dataBean);

                        PostBean postBean = new PostBean();
                        postBean.setMac(MacUtils.getMac(getContext()));
                        postBean.setBraceletNo(editText2.getText().toString().trim().replace(" ", ""));
                        postBean.setInjuryTime(DateUtils.stampToDate(new Date().getTime()));
                        postBean.setPatientName(nameTv.getText().toString().trim());
                        postBean.setIdentityNo(idcardEt.getText().toString().trim());
                        postBean.setBloodPressureMax(Integer.parseInt(textView14.getText().toString()));
                        postBean.setBloodPressureMin(Integer.parseInt(textView16.getText().toString()));
                        postBean.setBodyTemperature(Float.parseFloat(textView25.getText().toString()));
                        postBean.setOxygenSaturation(Integer.parseInt(textView19.getText().toString()));
                        postBean.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                        postBean.setBreathe(Integer.parseInt(textView22.getText().toString()));//呼吸率
                        postBean.setEyeOpening(String.valueOf(eye));
                        postBean.setLanguageResponse(String.valueOf(yuyan));
                        postBean.setActionResponse(String.valueOf(yundong));
                        postBean.setInjuryScore(shangqingLevel);
                        postBean.setIsChecked(0);//是否二次检伤
                        postBean.setHead(toubu ? 1 : 0);
                        postBean.setNeck(jingbu ? 1 : 0);
                        postBean.setChest(xiongbu ? 1 : 0);
                        postBean.setAbdomen(fubu ? 1 : 0);
                        postBean.setRightUpperLimb(youshangzhi ? 1 : 0);
                        postBean.setRightLowLimb(youxiazhi ? 1 : 0);
                        postBean.setLeftUpperLimb(zuoshangzhi ? 1 : 0);
                        postBean.setLeftLowLimb(zuoxiazhi ? 1 : 0);
                        postBean.setBack(beibu ? 1 : 0);
                        postBean.setHeartImgSourceData(mIntegerCopyOnWriteArrayList);
                        upload(postBean);

                        PostBean2 postBean2 = new PostBean2();
                        postBean2.setMac(MacUtils.getMac(getContext()));
                        postBean2.setBraceletNo(editText2.getText().toString().trim().replace(" ", ""));
                        postBean2.setInjuryTime(DateUtils.stampToDate(new Date().getTime()));
                        postBean2.setPatientName(nameTv.getText().toString().trim());
                        postBean2.setIdentityNo(idcardEt.getText().toString().trim());
                        postBean2.setBloodPressureMax(Integer.parseInt(textView14.getText().toString()));
                        postBean2.setBloodPressureMin(Integer.parseInt(textView16.getText().toString()));
                        postBean2.setBodyTemperature(Float.parseFloat(textView25.getText().toString()));
                        postBean2.setOxygenSaturation(Integer.parseInt(textView19.getText().toString()));
                        postBean2.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                        postBean2.setBreathe(Integer.parseInt(textView22.getText().toString()));//呼吸率
                        postBean2.setEyeOpening(String.valueOf(eye));
                        postBean2.setLanguageResponse(String.valueOf(yuyan));
                        postBean2.setActionResponse(String.valueOf(yundong));
                        postBean2.setInjuryScore(shangqingLevel);
                        postBean2.setIsChecked(0);//是否二次检伤
                        postBean2.setHead(toubu ? 1 : 0);
                        postBean2.setNeck(jingbu ? 1 : 0);
                        postBean2.setChest(xiongbu ? 1 : 0);
                        postBean2.setAbdomen(fubu ? 1 : 0);
                        postBean2.setRightUpperLimb(youshangzhi ? 1 : 0);
                        postBean2.setRightLowLimb(youxiazhi ? 1 : 0);
                        postBean2.setLeftUpperLimb(zuoshangzhi ? 1 : 0);
                        postBean2.setLeftLowLimb(zuoxiazhi ? 1 : 0);
                        postBean2.setBack(beibu ? 1 : 0);
                        postBean2.setHeartImgSourceData(mIntegerCopyOnWriteArrayList);
                        Log.e(TAG, "heartDatasize保存的====>>: " + mIntegerCopyOnWriteArrayList.size());
                        upload2(postBean2);

                    } else {//插入新数据
                        DataBean dataBean = new DataBean();
                        Date date = new Date();
                        String numStr = editText2.getText().toString().trim().replace(" ", "");

                        dataBean.setNumber(numStr);
                        dataBean.setName(nameTv.getText().toString());
                        int shousuoyaLevel = 0;

                        if (!textView14.getText().toString().equals("-")) {
                            if (Integer.parseInt(textView14.getText().toString()) > 89) {
                                shousuoyaLevel = 4;
                            } else if (Integer.parseInt(textView14.getText().toString()) <= 89 && Integer.parseInt(textView14.getText().toString()) >= 76) {
                                shousuoyaLevel = 3;
                            } else if (Integer.parseInt(textView14.getText().toString()) <= 75 && Integer.parseInt(textView14.getText().toString()) >= 50) {
                                shousuoyaLevel = 2;
                            } else if (Integer.parseInt(textView14.getText().toString()) >= 1 && Integer.parseInt(textView14.getText().toString()) <= 49) {
                                shousuoyaLevel = 1;
                            }
                        } else {
//                            Toast.makeText(getContext(), "请测量血压", Toast.LENGTH_LONG).show();
                            mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量血压！");
                            mNormalDialog.show();
                            mNormalDialog.getWindow().setLayout(1000, 500);
                            return;
                        }

                        int huxilv = 0;
                        if (!textView22.getText().toString().equals("--")) {
                            if (Integer.parseInt(textView22.getText().toString()) > 29) {
                                huxilv = 3;
                            } else if (Integer.parseInt(textView22.getText().toString()) >= 10 && Integer.parseInt(textView22.getText().toString()) <= 29) {
                                huxilv = 4;
                            } else if (Integer.parseInt(textView22.getText().toString()) >= 6 && Integer.parseInt(textView22.getText().toString()) <= 9) {
                                huxilv = 2;
                            } else if (Integer.parseInt(textView22.getText().toString()) >= 4 && Integer.parseInt(textView22.getText().toString()) <= 5) {
                                huxilv = 1;
                            }
                        } else {
//                            Toast.makeText(getContext(), "请测量呼吸率", Toast.LENGTH_LONG).show();
                            mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量呼吸率！");
                            mNormalDialog.show();
                            mNormalDialog.getWindow().setLayout(1000, 500);
                        }

                        int shenzhipanduan = 0;
                        int shenzhi = eye + yuyan + yundong;
                        if (shenzhi >= 13 && shenzhi <= 15) {
                            shenzhipanduan = 4;
                        } else if (shenzhi >= 9 && shenzhi <= 12) {
                            shenzhipanduan = 3;
                        } else if (shenzhi >= 6 && shenzhi <= 8) {
                            shenzhipanduan = 2;
                        } else if (shenzhi >= 4 && shenzhi <= 5) {
                            shenzhipanduan = 1;
                        }

                        int shangqingLevel = shenzhipanduan + huxilv + shousuoyaLevel;
                        if (shangqingLevel == 12) {
                            dataBean.setScoreLevel(1);
                        } else if (shangqingLevel >= 10) {
                            dataBean.setScoreLevel(2);
                        } else if (shangqingLevel >= 6) {
                            dataBean.setScoreLevel(3);
                        } else {
                            dataBean.setScoreLevel(4);
                        }

                        dataBean.setScore(shangqingLevel);
                        dataBean.setBloodType(xuexingStr);
                        dataBean.setBloodPressureH(Integer.parseInt(textView14.getText().toString()));
                        dataBean.setBloodPressureL(Integer.parseInt(textView16.getText().toString()));
                        dataBean.setBloodOxygen(Integer.parseInt(textView19.getText().toString()));
                        dataBean.setTemperature(Float.parseFloat(textView25.getText().toString()));
                        dataBean.setChest(xiongbu);
                        dataBean.setRightUpperLimb(youshangzhi);
                        dataBean.setRightLowLimb(youxiazhi);
                        dataBean.setHead(toubu);
                        dataBean.setRespiratoryRate(Integer.parseInt(textView22.getText().toString()));
                        dataBean.setNeck(jingbu);
                        dataBean.setLeftUpperLimb(zuoshangzhi);
                        dataBean.setAbdomen(fubu);
                        dataBean.setLeftLowLimb(zuoxiazhi);
                        dataBean.setEye(eye);
                        dataBean.setSay(yuyan);
                        dataBean.setSport(yundong);
                        dataBean.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                        dataBean.setCreateTime(date);
                        MyApplication.getDaoSession().insert(dataBean);//新增数据


                        PostBean postBean = new PostBean();
                        postBean.setMac(MacUtils.getMac(getContext()));
                        postBean.setBraceletNo(editText2.getText().toString().trim().replace(" ", ""));
                        postBean.setInjuryTime(DateUtils.stampToDate(new Date().getTime()));
                        postBean.setPatientName(nameTv.getText().toString().trim());
                        postBean.setIdentityNo(idcardEt.getText().toString().trim());
                        postBean.setBloodPressureMax(Integer.parseInt(textView14.getText().toString()));
                        postBean.setBloodPressureMin(Integer.parseInt(textView16.getText().toString()));
                        postBean.setBodyTemperature(Float.parseFloat(textView25.getText().toString()));
                        postBean.setOxygenSaturation(Integer.parseInt(textView19.getText().toString()));
                        postBean.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                        postBean.setBreathe(Integer.parseInt(textView22.getText().toString()));//呼吸率
                        postBean.setEyeOpening(String.valueOf(eye));
                        postBean.setLanguageResponse(String.valueOf(yuyan));
                        postBean.setActionResponse(String.valueOf(yundong));
                        postBean.setInjuryScore(shangqingLevel);
                        postBean.setIsChecked(0);//是否二次检伤
                        postBean.setHead(toubu ? 1 : 0);
                        postBean.setNeck(jingbu ? 1 : 0);
                        postBean.setChest(xiongbu ? 1 : 0);
                        postBean.setAbdomen(fubu ? 1 : 0);
                        postBean.setRightUpperLimb(youshangzhi ? 1 : 0);
                        postBean.setRightLowLimb(youxiazhi ? 1 : 0);
                        postBean.setLeftUpperLimb(zuoshangzhi ? 1 : 0);
                        postBean.setLeftLowLimb(zuoxiazhi ? 1 : 0);
                        postBean.setBack(beibu ? 1 : 0);
                        postBean.setHeartImgSourceData(mIntegerCopyOnWriteArrayList);
                        upload(postBean);

                        PostBean2 postBean2 = new PostBean2();
                        postBean2.setMac(MacUtils.getMac(getContext()));
                        postBean2.setBraceletNo(editText2.getText().toString().trim().replace(" ", ""));
                        postBean2.setInjuryTime(DateUtils.stampToDate(new Date().getTime()));
                        postBean2.setPatientName(nameTv.getText().toString().trim());
                        postBean2.setIdentityNo(idcardEt.getText().toString().trim());
                        postBean2.setBloodPressureMax(Integer.parseInt(textView14.getText().toString()));
                        postBean2.setBloodPressureMin(Integer.parseInt(textView16.getText().toString()));
                        postBean2.setBodyTemperature(Float.parseFloat(textView25.getText().toString()));
                        postBean2.setOxygenSaturation(Integer.parseInt(textView19.getText().toString()));
                        postBean2.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                        postBean2.setBreathe(Integer.parseInt(textView22.getText().toString()));//呼吸率
                        postBean2.setEyeOpening(String.valueOf(eye));
                        postBean2.setLanguageResponse(String.valueOf(yuyan));
                        postBean2.setActionResponse(String.valueOf(yundong));
                        postBean2.setInjuryScore(shangqingLevel);
                        postBean2.setIsChecked(0);//是否二次检伤
                        postBean2.setHead(toubu ? 1 : 0);
                        postBean2.setNeck(jingbu ? 1 : 0);
                        postBean2.setChest(xiongbu ? 1 : 0);
                        postBean2.setAbdomen(fubu ? 1 : 0);
                        postBean2.setRightUpperLimb(youshangzhi ? 1 : 0);
                        postBean2.setRightLowLimb(youxiazhi ? 1 : 0);
                        postBean2.setLeftUpperLimb(zuoshangzhi ? 1 : 0);
                        postBean2.setLeftLowLimb(zuoxiazhi ? 1 : 0);
                        postBean2.setHeartImgSourceData(mIntegerCopyOnWriteArrayList);
                        postBean2.setBack(beibu ? 1 : 0);
                        Log.e(TAG, "heartDatasize===保存=>>: " + mIntegerCopyOnWriteArrayList.size());
                        upload2(postBean2);
                    }
                }
                timer.start();
                saveDataDialog = new SaveDataDialog(getContext(), R.style.TipDialog);
                saveDataDialog.show();
                saveDataDialog.getWindow().setLayout(1000, 500);

                mDataBeans = MyApplication.getDaoSession().getDataBeanDao().queryBuilder()
                        .where(DataBeanDao.Properties.IsChecked.eq(true))
                        .orderAsc(DataBeanDao.Properties.CreateTime)
                        .build().list();

                List<DataBean> listSave = new ArrayList<>();
                if (mDataBeans.size() > 0) {
                    for (int i1 = 0; i1 < mDataBeans.size(); i1++) {
                        if ((new Date().getTime() - mDataBeans.get(i1).getCreateTime().getTime()) / 1000 / 60 / 60 <= 5) {
                            listSave.add(mDataBeans.get(i1));
                        }
                    }
                }

                mainRvAdapter.setDataBeans(listSave);
                mainRvAdapter.notifyDataSetChanged();

                EventBus.getDefault().post(new MesEventCount(listSave.size()));

                break;
            case R.id.erjian_tv:
                if (editText2.getText().toString().length() != 6) {
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "手环号为6位！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (idcardEt.getText().toString().length() > 0) {
                    if (idcardEt.getText().toString().length() != 18) {
                        mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "身份证编号为18位！");
                        mNormalDialog.show();
                        mNormalDialog.getWindow().setLayout(1000, 500);
                        return;
                    }
                }
                //加入二检  || xuexing.getText().toString().equals("全部") || xuexing.getText().toString().equals("血型")
                if (editText2.getText().toString().isEmpty()
                ) {
//                    Toast.makeText(getContext(), "请输入个人信息", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请输入个人信息！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (eye == 0 || yuyan == 0 || yundong == 0) {//|| xuexing.getText().toString().equals("全部") || xuexing.getText().toString().equals("血型")
//                    Toast.makeText(getContext(), "请先补充检伤信息！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请先补充检伤信息！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (TextUtils.isEmpty(textView4.getText().toString())) {
//                    Toast.makeText(getContext(), "请先补充检伤信息！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请先补充检伤信息！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (textView19.getText().toString().equals("--")) {
//                    Toast.makeText(getContext(), "请测量血氧！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量血氧！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (textView22.getText().toString().equals("--")) {
//                    Toast.makeText(getContext(), "请测量呼吸率！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量呼吸率！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                if (textView25.getText().toString().equals("--")) {
//                    Toast.makeText(getContext(), "请测量体温！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量体温！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    return;
                }
                //查询数据最后一条数据
                List<DataBean> list = MyApplication.getDaoSession().getDataBeanDao().queryBuilder()
                        .where(DataBeanDao.Properties.Number.eq(editText2.getText().toString().trim().replace(" ", "")))
                        .build().list();
                if (list.size() > 0) {//如果保存过并且ischeck=false
                    DataBean dataBeanOld = list.get(0);
                    if (!dataBeanOld.getIsChecked()) {//更新二检标识
                        Log.d(TAG, "onClick: " + "已保存过，但没有二检" + dataBeanOld.getIsChecked());
                        DataBean dataBean = new DataBean();
                        Date date = new Date();
                        dataBean.setNumber(editText2.getText().toString().replace(" ", ""));
                        dataBean.setName(nameTv.getText().toString());
                        int shousuoyaLevel = 0;

                        if (!textView14.getText().toString().equals("-")) {
                            if (Integer.parseInt(textView14.getText().toString()) > 89) {
                                shousuoyaLevel = 4;
                            } else if (Integer.parseInt(textView14.getText().toString()) <= 89 && Integer.parseInt(textView14.getText().toString()) >= 76) {
                                shousuoyaLevel = 3;
                            } else if (Integer.parseInt(textView14.getText().toString()) <= 75 && Integer.parseInt(textView14.getText().toString()) >= 50) {
                                shousuoyaLevel = 2;
                            } else if (Integer.parseInt(textView14.getText().toString()) >= 1 && Integer.parseInt(textView14.getText().toString()) <= 49) {
                                shousuoyaLevel = 1;
                            }
                        } else {
//                            Toast.makeText(getContext(), "请测量血压", Toast.LENGTH_LONG).show();
                            mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量血压！");
                            mNormalDialog.show();
                            mNormalDialog.getWindow().setLayout(1000, 500);
                            return;
                        }

                        int huxilv = 0;
                        if (!textView22.getText().toString().equals("--")) {
                            if (Integer.parseInt(textView22.getText().toString()) > 29) {
                                huxilv = 3;
                            } else if (Integer.parseInt(textView22.getText().toString()) >= 10 && Integer.parseInt(textView22.getText().toString()) <= 29) {
                                huxilv = 4;
                            } else if (Integer.parseInt(textView22.getText().toString()) >= 6 && Integer.parseInt(textView22.getText().toString()) <= 9) {
                                huxilv = 2;
                            } else if (Integer.parseInt(textView22.getText().toString()) >= 4 && Integer.parseInt(textView22.getText().toString()) <= 5) {
                                huxilv = 1;
                            }
                        } else {
//                            Toast.makeText(getContext(), "请测量呼吸率", Toast.LENGTH_LONG).show();
                            mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量呼吸率！");
                            mNormalDialog.show();
                            mNormalDialog.getWindow().setLayout(1000, 500);
                        }

                        int shenzhipanduan = 0;
                        int shenzhi = eye + yuyan + yundong;
                        if (shenzhi >= 13 && shenzhi <= 15) {
                            shenzhipanduan = 4;
                        } else if (shenzhi >= 9 && shenzhi <= 12) {
                            shenzhipanduan = 3;
                        } else if (shenzhi >= 6 && shenzhi <= 8) {
                            shenzhipanduan = 2;
                        } else if (shenzhi >= 4 && shenzhi <= 5) {
                            shenzhipanduan = 1;
                        }

                        int shangqingLevel = shenzhipanduan + huxilv + shousuoyaLevel;
                        if (shangqingLevel == 12) {
                            dataBean.setScoreLevel(1);
                        } else if (shangqingLevel >= 10) {
                            dataBean.setScoreLevel(2);
                        } else if (shangqingLevel >= 6) {
                            dataBean.setScoreLevel(3);
                        } else {
                            dataBean.setScoreLevel(4);
                        }
                        dataBean.setScore(shangqingLevel);
                        dataBean.setBloodType(xuexingStr);
                        dataBean.setBloodPressureH(Integer.parseInt(textView14.getText().toString()));
                        dataBean.setBloodPressureL(Integer.parseInt(textView16.getText().toString()));
                        dataBean.setBloodOxygen(Integer.parseInt(textView19.getText().toString()));
                        dataBean.setTemperature(Float.parseFloat(textView25.getText().toString()));
                        dataBean.setChest(xiongbu);
                        dataBean.setRightUpperLimb(youshangzhi);
                        dataBean.setRespiratoryRate(Integer.parseInt(textView22.getText().toString()));
                        dataBean.setRightLowLimb(youxiazhi);
                        dataBean.setHead(toubu);
                        dataBean.setNeck(jingbu);
                        dataBean.setLeftUpperLimb(zuoshangzhi);
                        dataBean.setAbdomen(fubu);
                        dataBean.setLeftLowLimb(zuoxiazhi);
                        dataBean.setEye(eye);
                        dataBean.setSay(yuyan);
                        dataBean.setSport(yundong);
                        dataBean.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                        dataBean.setCreateTime(date);
                        dataBean.setIsChecked(true);//关键设置这个为ture
                        dataBean.setId(dataBeanOld.getId());//
                        //新数据替换旧数据
                        MyApplication.getDaoSession().getDataBeanDao().update(dataBean);

                        PostBean postBean = new PostBean();
                        postBean.setMac(MacUtils.getMac(getContext()));
                        postBean.setBraceletNo(editText2.getText().toString().trim().replace(" ", ""));
                        postBean.setInjuryTime(DateUtils.stampToDate(new Date().getTime()));
                        postBean.setPatientName(nameTv.getText().toString().trim());
                        postBean.setIdentityNo(idcardEt.getText().toString().trim());
                        postBean.setBloodPressureMax(Integer.parseInt(textView14.getText().toString()));
                        postBean.setBloodPressureMin(Integer.parseInt(textView16.getText().toString()));
                        postBean.setBodyTemperature(Float.parseFloat(textView25.getText().toString()));
                        postBean.setOxygenSaturation(Integer.parseInt(textView19.getText().toString()));
                        postBean.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                        postBean.setBreathe(Integer.parseInt(textView22.getText().toString()));//呼吸率
                        postBean.setEyeOpening(String.valueOf(eye));
                        postBean.setLanguageResponse(String.valueOf(yuyan));
                        postBean.setActionResponse(String.valueOf(yundong));
                        postBean.setInjuryScore(shangqingLevel);
                        postBean.setIsChecked(1);//是否二次检伤
                        postBean.setHead(toubu ? 1 : 0);
                        postBean.setNeck(jingbu ? 1 : 0);
                        postBean.setChest(xiongbu ? 1 : 0);
                        postBean.setAbdomen(fubu ? 1 : 0);
                        postBean.setRightUpperLimb(youshangzhi ? 1 : 0);
                        postBean.setRightLowLimb(youxiazhi ? 1 : 0);
                        postBean.setLeftUpperLimb(zuoshangzhi ? 1 : 0);
                        postBean.setLeftLowLimb(zuoxiazhi ? 1 : 0);
                        postBean.setBack(beibu ? 1 : 0);
                        postBean.setHeartImgSourceData(mIntegerCopyOnWriteArrayList);
                        upload(postBean);

                        PostBean2 postBean2 = new PostBean2();
                        postBean2.setMac(MacUtils.getMac(getContext()));
                        postBean2.setBraceletNo(editText2.getText().toString().trim().replace(" ", ""));
                        postBean2.setInjuryTime(DateUtils.stampToDate(new Date().getTime()));
                        postBean2.setPatientName(nameTv.getText().toString().trim());
                        postBean2.setIdentityNo(idcardEt.getText().toString().trim());
                        postBean2.setBloodPressureMax(Integer.parseInt(textView14.getText().toString()));
                        postBean2.setBloodPressureMin(Integer.parseInt(textView16.getText().toString()));
                        postBean2.setBodyTemperature(Float.parseFloat(textView25.getText().toString()));
                        postBean2.setOxygenSaturation(Integer.parseInt(textView19.getText().toString()));
                        postBean2.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                        postBean2.setBreathe(Integer.parseInt(textView22.getText().toString()));//呼吸率
                        postBean2.setEyeOpening(String.valueOf(eye));
                        postBean2.setLanguageResponse(String.valueOf(yuyan));
                        postBean2.setActionResponse(String.valueOf(yundong));
                        postBean2.setInjuryScore(shangqingLevel);
                        postBean2.setIsChecked(1);//是否二次检伤
                        postBean2.setHead(toubu ? 1 : 0);
                        postBean2.setNeck(jingbu ? 1 : 0);
                        postBean2.setChest(xiongbu ? 1 : 0);
                        postBean2.setAbdomen(fubu ? 1 : 0);
                        postBean2.setRightUpperLimb(youshangzhi ? 1 : 0);
                        postBean2.setRightLowLimb(youxiazhi ? 1 : 0);
                        postBean2.setLeftUpperLimb(zuoshangzhi ? 1 : 0);
                        postBean2.setLeftLowLimb(zuoxiazhi ? 1 : 0);
                        postBean2.setHeartImgSourceData(mIntegerCopyOnWriteArrayList);
                        postBean2.setBack(beibu ? 1 : 0);
                        upload2(postBean2);

                        JoinCheckDialog joinCheckDialog = new JoinCheckDialog(getContext(), R.style.TipDialog);
                        joinCheckDialog.show();
                        joinCheckDialog.getWindow().setLayout(1000, 500);
                    } else {//ischeck=true
                        Log.d(TAG, "onClick: " + "已保存过，有二检");
//                        Toast.makeText(getContext(), "已加入过二检，无需重复添加", Toast.LENGTH_SHORT).show();
                        mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "已加入过二检，无需重复添加！");
                        mNormalDialog.show();
                        mNormalDialog.getWindow().setLayout(1000, 500);
                    }
                } else {
                    DataBean dataBean = new DataBean();
                    Date date = new Date();
                    dataBean.setNumber(editText2.getText().toString().replace(" ", ""));
                    dataBean.setName(nameTv.getText().toString());
                    int shousuoyaLevel = 0;

                    if (!textView14.getText().toString().equals("-")) {
                        if (Integer.parseInt(textView14.getText().toString()) > 89) {
                            shousuoyaLevel = 4;
                        } else if (Integer.parseInt(textView14.getText().toString()) <= 89 && Integer.parseInt(textView14.getText().toString()) >= 76) {
                            shousuoyaLevel = 3;
                        } else if (Integer.parseInt(textView14.getText().toString()) <= 75 && Integer.parseInt(textView14.getText().toString()) >= 50) {
                            shousuoyaLevel = 2;
                        } else if (Integer.parseInt(textView14.getText().toString()) >= 1 && Integer.parseInt(textView14.getText().toString()) <= 49) {
                            shousuoyaLevel = 1;
                        }
                    } else {
//                        Toast.makeText(getContext(), "请测量血压", Toast.LENGTH_LONG).show();
                        mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量血压！");
                        mNormalDialog.show();
                        mNormalDialog.getWindow().setLayout(1000, 500);
                        return;
                    }

                    int huxilv = 0;
                    if (!textView22.getText().toString().equals("--")) {
                        if (Integer.parseInt(textView22.getText().toString()) > 29) {
                            huxilv = 3;
                        } else if (Integer.parseInt(textView22.getText().toString()) >= 10 && Integer.parseInt(textView22.getText().toString()) <= 29) {
                            huxilv = 4;
                        } else if (Integer.parseInt(textView22.getText().toString()) >= 6 && Integer.parseInt(textView22.getText().toString()) <= 9) {
                            huxilv = 2;
                        } else if (Integer.parseInt(textView22.getText().toString()) >= 4 && Integer.parseInt(textView22.getText().toString()) <= 5) {
                            huxilv = 1;
                        }
                    } else {
//                        Toast.makeText(getContext(), "请测量呼吸率", Toast.LENGTH_LONG).show();
                        mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量呼吸率！");
                        mNormalDialog.show();
                        mNormalDialog.getWindow().setLayout(1000, 500);
                    }
                    int shenzhipanduan = 0;
                    int shenzhi = eye + yuyan + yundong;
                    if (shenzhi >= 13 && shenzhi <= 15) {
                        shenzhipanduan = 4;
                    } else if (shenzhi >= 9 && shenzhi <= 12) {
                        shenzhipanduan = 3;
                    } else if (shenzhi >= 6 && shenzhi <= 8) {
                        shenzhipanduan = 2;
                    } else if (shenzhi >= 4 && shenzhi <= 5) {
                        shenzhipanduan = 1;
                    }

                    int shangqingLevel = shenzhipanduan + huxilv + shousuoyaLevel;
                    if (shangqingLevel == 12) {
                        dataBean.setScoreLevel(1);
                    } else if (shangqingLevel >= 10) {
                        dataBean.setScoreLevel(2);
                    } else if (shangqingLevel >= 6) {
                        dataBean.setScoreLevel(3);
                    } else {
                        dataBean.setScoreLevel(4);
                    }
                    dataBean.setScore(shangqingLevel);
                    dataBean.setBloodType(xuexingStr);
                    dataBean.setBloodPressureH(Integer.parseInt(textView14.getText().toString()));
                    dataBean.setBloodPressureL(Integer.parseInt(textView16.getText().toString()));
                    dataBean.setBloodOxygen(Integer.parseInt(textView19.getText().toString()));
                    dataBean.setTemperature(Float.parseFloat(textView25.getText().toString()));
                    dataBean.setChest(xiongbu);
                    dataBean.setRightUpperLimb(youshangzhi);
                    dataBean.setRightLowLimb(youxiazhi);
                    dataBean.setHead(toubu);
                    dataBean.setNeck(jingbu);
                    dataBean.setLeftUpperLimb(zuoshangzhi);
                    dataBean.setAbdomen(fubu);
                    dataBean.setLeftLowLimb(zuoxiazhi);
                    dataBean.setEye(eye);
                    dataBean.setSay(yuyan);
                    dataBean.setRespiratoryRate(Integer.parseInt(textView22.getText().toString()));
                    dataBean.setSport(yundong);
                    dataBean.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                    dataBean.setCreateTime(date);
                    dataBean.setIsChecked(true);//关键设置这个为ture
                    MyApplication.getDaoSession().insert(dataBean);//新增数据

                    PostBean postBean = new PostBean();
                    postBean.setMac(MacUtils.getMac(getContext()));
                    postBean.setBraceletNo(editText2.getText().toString().trim().replace(" ", ""));
                    postBean.setInjuryTime(DateUtils.stampToDate(new Date().getTime()));
                    postBean.setPatientName(nameTv.getText().toString().trim());
                    postBean.setIdentityNo(idcardEt.getText().toString().trim());
                    postBean.setBloodPressureMax(Integer.parseInt(textView14.getText().toString()));
                    postBean.setBloodPressureMin(Integer.parseInt(textView16.getText().toString()));
                    postBean.setBodyTemperature(Float.parseFloat(textView25.getText().toString()));
                    postBean.setOxygenSaturation(Integer.parseInt(textView19.getText().toString()));
                    postBean.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                    postBean.setBreathe(Integer.parseInt(textView22.getText().toString()));//呼吸率
                    postBean.setEyeOpening(String.valueOf(eye));
                    postBean.setLanguageResponse(String.valueOf(yuyan));
                    postBean.setActionResponse(String.valueOf(yundong));
                    postBean.setInjuryScore(shangqingLevel);
                    postBean.setIsChecked(1);//是否二次检伤
                    postBean.setHead(toubu ? 1 : 0);
                    postBean.setNeck(jingbu ? 1 : 0);
                    postBean.setChest(xiongbu ? 1 : 0);
                    postBean.setAbdomen(fubu ? 1 : 0);
                    postBean.setRightUpperLimb(youshangzhi ? 1 : 0);
                    postBean.setRightLowLimb(youxiazhi ? 1 : 0);
                    postBean.setLeftUpperLimb(zuoshangzhi ? 1 : 0);
                    postBean.setLeftLowLimb(zuoxiazhi ? 1 : 0);
                    postBean.setBack(beibu ? 1 : 0);
                    postBean.setHeartImgSourceData(mIntegerCopyOnWriteArrayList);
                    upload(postBean);

                    PostBean2 postBean2 = new PostBean2();
                    postBean2.setMac(MacUtils.getMac(getContext()));
                    postBean2.setBraceletNo(editText2.getText().toString().trim().replace(" ", ""));
                    postBean2.setInjuryTime(DateUtils.stampToDate(new Date().getTime()));
                    postBean2.setPatientName(nameTv.getText().toString().trim());
                    postBean2.setIdentityNo(idcardEt.getText().toString().trim());
                    postBean2.setBloodPressureMax(Integer.parseInt(textView14.getText().toString()));
                    postBean2.setBloodPressureMin(Integer.parseInt(textView16.getText().toString()));
                    postBean2.setBodyTemperature(Float.parseFloat(textView25.getText().toString()));
                    postBean2.setOxygenSaturation(Integer.parseInt(textView19.getText().toString()));
                    postBean2.setHeartRate(Integer.parseInt(textView11.getText().toString()));
                    postBean2.setBreathe(Integer.parseInt(textView22.getText().toString()));//呼吸率
                    postBean2.setEyeOpening(String.valueOf(eye));
                    postBean2.setLanguageResponse(String.valueOf(yuyan));
                    postBean2.setActionResponse(String.valueOf(yundong));
                    postBean2.setInjuryScore(shangqingLevel);
                    postBean2.setIsChecked(1);//是否二次检伤
                    postBean2.setHead(toubu ? 1 : 0);
                    postBean2.setNeck(jingbu ? 1 : 0);
                    postBean2.setChest(xiongbu ? 1 : 0);
                    postBean2.setAbdomen(fubu ? 1 : 0);
                    postBean2.setRightUpperLimb(youshangzhi ? 1 : 0);
                    postBean2.setRightLowLimb(youxiazhi ? 1 : 0);
                    postBean2.setLeftUpperLimb(zuoshangzhi ? 1 : 0);
                    postBean2.setLeftLowLimb(zuoxiazhi ? 1 : 0);
                    postBean2.setHeartImgSourceData(mIntegerCopyOnWriteArrayList);
                    postBean2.setBack(beibu ? 1 : 0);
                    upload2(postBean2);
                }

                //时间差
                mDataBeans = MyApplication.getDaoSession().getDataBeanDao().queryBuilder()
                        .where(DataBeanDao.Properties.IsChecked.eq(true))
                        .orderAsc(DataBeanDao.Properties.CreateTime)
                        .build().list();

                List<DataBean> listTemp = new ArrayList<>();
                if (mDataBeans.size() > 0) {
                    for (int i1 = 0; i1 < mDataBeans.size(); i1++) {
                        if ((new Date().getTime() - mDataBeans.get(i1).getCreateTime().getTime()) / 1000 / 60 / 60 <= 5) {
                            listTemp.add(mDataBeans.get(i1));
                        }
                    }
                }

                mainRvAdapter.setDataBeans(listTemp);
                mainRvAdapter.notifyDataSetChanged();
                EventBus.getDefault().post(new MesEventCount(listTemp.size()));

//                xiongbu = false;
//                youshangzhi = false;
//                youxiazhi = false;
//                toubu = false;
//                jingbu = false;
//                zuoshangzhi = false;
//                fubu = false;
//                zuoxiazhi = false;
                break;
            case R.id.tiwen_tv:
                mSerialPortService.sendBytes(MakePackage.makeBytes());
                break;
            case R.id.xueya_tv:
                mSerialPortService1.sendBytes(MakePackage.makeBytes1());
                break;
        }
    }

    /**
     * 身体热点图
     */
    private void changeBody(int type) {
        switch (type) {
            case 0://胸
                xiongbu = !xiongbu;

                if (xiongbu) {
                    if (beibu) {
                        chestSelect.setVisibility(View.VISIBLE);//绿色
                    } else {
                        chestSelect.setVisibility(View.VISIBLE);
                    }
                } else {
                    if (beibu) {
                        chestSelect.setVisibility(View.VISIBLE);//绿色
                    } else {
                        chestSelect.setVisibility(View.INVISIBLE);
                    }
                }

                if (xiongbu) {//true
                    btnChest.setImageResource(R.mipmap.btn_chest_error);

                } else {
                    btnChest.setImageResource(R.mipmap.btn_chest);
                }

                break;
            case 8:
                beibu = !beibu;

                if (xiongbu) {
                    if (beibu) {
                        chestSelect.setVisibility(View.VISIBLE);
                    } else {
                        chestSelect.setVisibility(View.VISIBLE);
                    }
                } else {
                    if (beibu) {
                        chestSelect.setVisibility(View.VISIBLE);
                    } else {
                        chestSelect.setVisibility(View.INVISIBLE);
                    }
                }

                if (beibu) {
                    btnBack.setImageResource(R.mipmap.back_error);

                } else {//变红
                    btnBack.setImageResource(R.mipmap.back_normal);

                }
                break;
            case 1://右上肢
                if (youshangzhi) {
                    btnRightUp.setImageResource(R.mipmap.youshangzhi_ok);
                    rightupSelect.setVisibility(View.INVISIBLE);
                } else {
                    btnRightUp.setImageResource(R.mipmap.btn_right_upper_limb);
                    rightupSelect.setVisibility(View.VISIBLE);
                }
                youshangzhi = !youshangzhi;
                break;
            case 2://右下肢
                if (youxiazhi) {
                    btnRightLow.setImageResource(R.mipmap.btn_right_lower_limb);
                    rightlowSelect.setVisibility(View.INVISIBLE);
                } else {
                    btnRightLow.setImageResource(R.mipmap.btn_right_lower_limb_error);
                    rightlowSelect.setVisibility(View.VISIBLE);
                }
                youxiazhi = !youxiazhi;
                break;
            case 3:
                if (toubu) {
                    btnHeadOk1.setImageResource(R.mipmap.btn_head_ok);
                    headSelect.setVisibility(View.INVISIBLE);
                } else {
                    btnHeadOk1.setImageResource(R.mipmap.btn_head_error);
                    headSelect.setVisibility(View.VISIBLE);
                }
                toubu = !toubu;
                break;
            case 4:
                if (jingbu) {
                    btnNeck1.setImageResource(R.mipmap.btn_neck);
                    neckSelect.setVisibility(View.INVISIBLE);
                } else {
                    btnNeck1.setImageResource(R.mipmap.btn_neck_error);
                    neckSelect.setVisibility(View.VISIBLE);
                }
                jingbu = !jingbu;
                break;
            case 5:
                if (zuoshangzhi) {
                    btnLeftup.setImageResource(R.mipmap.btn_left_upper_limb);
                    leftupSelect.setVisibility(View.INVISIBLE);
                } else {
                    btnLeftup.setImageResource(R.mipmap.btn_left_upper_limb_error);
                    leftupSelect.setVisibility(View.VISIBLE);
                }
                zuoshangzhi = !zuoshangzhi;
                break;
            case 6:
                if (fubu) {
                    btnAbdomen1.setImageResource(R.mipmap.btn_abdomen);
                    fubuSelect.setVisibility(View.INVISIBLE);
                } else {
                    btnAbdomen1.setImageResource(R.mipmap.btn_abdomen_error);
                    fubuSelect.setVisibility(View.VISIBLE);
                }
                fubu = !fubu;
                break;
            case 7:
                if (zuoxiazhi) {
                    btnLeftLow.setImageResource(R.mipmap.btn_left_lower_limb);
                    leftlowSelect.setVisibility(View.INVISIBLE);
                } else {
                    btnLeftLow.setImageResource(R.mipmap.btn_left_lower_limb_error);
                    leftlowSelect.setVisibility(View.VISIBLE);
                }
                zuoxiazhi = !zuoxiazhi;
                break;

            default:
                break;
        }

    }

    /**
     * 数据报警改变显示状态
     */
    private void changeStatus(int eye, int yuyan, int yundong) {
        int sum = eye + yuyan + yundong;
        if (sum < 10) {
            xueyaCl.setBackgroundResource(R.mipmap.warning_xueya);
            xueyangCl.setBackgroundResource(R.mipmap.warning_xueyang);
            huxiCl.setBackgroundResource(R.mipmap.warning_xueyang);
            tiwenCl.setBackgroundResource(R.mipmap.warning_xueyang);
            imageView.setImageResource(R.mipmap.tip_error);
            imageView3.setImageResource(R.mipmap.tip_error);
            imageView4.setImageResource(R.mipmap.tip_error);
            imageView5.setImageResource(R.mipmap.tip_error);
            imageView6.setImageResource(R.mipmap.tip_error);
            textView4.setTextColor(getResources().getColor(R.color.notes_main));
            textView6.setTextColor(getResources().getColor(R.color.notes_main));
            textView7.setTextColor(getResources().getColor(R.color.notes_main));
            textView8.setTextColor(getResources().getColor(R.color.notes_main));
            textView9.setTextColor(getResources().getColor(R.color.notes_main));
            textView10.setTextColor(getResources().getColor(R.color.notes_main));
            textView11.setTextColor(getResources().getColor(R.color.notes_main));
            textView12.setTextColor(getResources().getColor(R.color.notes_main));
            textView13.setTextColor(getResources().getColor(R.color.notes_main));
            textView14.setTextColor(getResources().getColor(R.color.notes_main));
            textView15.setTextColor(getResources().getColor(R.color.notes_main));
            textView16.setTextColor(getResources().getColor(R.color.notes_main));
            textView17.setTextColor(getResources().getColor(R.color.notes_main));
            textView18.setTextColor(getResources().getColor(R.color.notes_main));
            textView19.setTextColor(getResources().getColor(R.color.notes_main));
            textView20.setTextColor(getResources().getColor(R.color.notes_main));
            textView21.setTextColor(getResources().getColor(R.color.notes_main));
            textView22.setTextColor(getResources().getColor(R.color.notes_main));
            textView23.setTextColor(getResources().getColor(R.color.notes_main));
            textView24.setTextColor(getResources().getColor(R.color.notes_main));
            textView25.setTextColor(getResources().getColor(R.color.notes_main));
        } else {
            xueyaCl.setBackgroundResource(R.mipmap.bg_data);
            xueyangCl.setBackgroundResource(R.mipmap.bg_data);
            huxiCl.setBackgroundResource(R.mipmap.bg_data);
            tiwenCl.setBackgroundResource(R.mipmap.bg_data);
            imageView.setImageResource(R.mipmap.tip_data);
            imageView3.setImageResource(R.mipmap.tip_data);
            imageView4.setImageResource(R.mipmap.tip_data);
            imageView5.setImageResource(R.mipmap.tip_data);
            imageView6.setImageResource(R.mipmap.tip_data);
            textView4.setTextColor(getResources().getColor(R.color.bloodselect));
            textView6.setTextColor(getResources().getColor(R.color.bloodselect));
            textView7.setTextColor(getResources().getColor(R.color.bloodselect));
            textView8.setTextColor(getResources().getColor(R.color.bloodselect));
            textView9.setTextColor(getResources().getColor(R.color.heart));
            textView10.setTextColor(getResources().getColor(R.color.heart));
            textView11.setTextColor(getResources().getColor(R.color.heart));
            textView12.setTextColor(getResources().getColor(R.color.bloodselect));
            textView13.setTextColor(getResources().getColor(R.color.bloodselect));
            textView14.setTextColor(getResources().getColor(R.color.bloodselect));
            textView15.setTextColor(getResources().getColor(R.color.bloodselect));
            textView16.setTextColor(getResources().getColor(R.color.bloodselect));
            textView17.setTextColor(getResources().getColor(R.color.bloodselect));
            textView18.setTextColor(getResources().getColor(R.color.bloodselect));
            textView19.setTextColor(getResources().getColor(R.color.bloodselect));
            textView20.setTextColor(getResources().getColor(R.color.bloodselect));
            textView21.setTextColor(getResources().getColor(R.color.bloodselect));
            textView22.setTextColor(getResources().getColor(R.color.bloodselect));
            textView23.setTextColor(getResources().getColor(R.color.bloodselect));
            textView24.setTextColor(getResources().getColor(R.color.bloodselect));
            textView25.setTextColor(getResources().getColor(R.color.bloodselect));
        }
    }

    private void changeStatusMain(int sum) {
        Log.e(TAG, "changeStatusMain: " + sum);
        if (sum < 10) {
            xueyaCl.setBackgroundResource(R.mipmap.warning_xueya);
            xueyangCl.setBackgroundResource(R.mipmap.warning_xueyang);
            huxiCl.setBackgroundResource(R.mipmap.warning_xueyang);
            tiwenCl.setBackgroundResource(R.mipmap.warning_xueyang);
            imageView.setImageResource(R.mipmap.tip_error);
            imageView3.setImageResource(R.mipmap.tip_error);
            imageView4.setImageResource(R.mipmap.tip_error);
            imageView5.setImageResource(R.mipmap.tip_error);
            imageView6.setImageResource(R.mipmap.tip_error);
            textView4.setTextColor(getResources().getColor(R.color.notes_main));
            textView6.setTextColor(getResources().getColor(R.color.notes_main));
            textView7.setTextColor(getResources().getColor(R.color.notes_main));
            textView8.setTextColor(getResources().getColor(R.color.notes_main));
            textView9.setTextColor(getResources().getColor(R.color.notes_main));
            textView10.setTextColor(getResources().getColor(R.color.notes_main));
            textView11.setTextColor(getResources().getColor(R.color.notes_main));
            textView12.setTextColor(getResources().getColor(R.color.notes_main));
            textView13.setTextColor(getResources().getColor(R.color.notes_main));
            textView14.setTextColor(getResources().getColor(R.color.notes_main));
            textView15.setTextColor(getResources().getColor(R.color.notes_main));
            textView16.setTextColor(getResources().getColor(R.color.notes_main));
            textView17.setTextColor(getResources().getColor(R.color.notes_main));
            textView18.setTextColor(getResources().getColor(R.color.notes_main));
            textView19.setTextColor(getResources().getColor(R.color.notes_main));
            textView20.setTextColor(getResources().getColor(R.color.notes_main));
            textView21.setTextColor(getResources().getColor(R.color.notes_main));
            textView22.setTextColor(getResources().getColor(R.color.notes_main));
            textView23.setTextColor(getResources().getColor(R.color.notes_main));
            textView24.setTextColor(getResources().getColor(R.color.notes_main));
            textView25.setTextColor(getResources().getColor(R.color.notes_main));
        } else {
            xueyaCl.setBackgroundResource(R.mipmap.bg_data);
            xueyangCl.setBackgroundResource(R.mipmap.bg_data);
            huxiCl.setBackgroundResource(R.mipmap.bg_data);
            tiwenCl.setBackgroundResource(R.mipmap.bg_data);
            imageView.setImageResource(R.mipmap.tip_data);
            imageView3.setImageResource(R.mipmap.tip_data);
            imageView4.setImageResource(R.mipmap.tip_data);
            imageView5.setImageResource(R.mipmap.tip_data);
            imageView6.setImageResource(R.mipmap.tip_data);
            textView4.setTextColor(getResources().getColor(R.color.bloodselect));
            textView6.setTextColor(getResources().getColor(R.color.bloodselect));
            textView7.setTextColor(getResources().getColor(R.color.bloodselect));
            textView8.setTextColor(getResources().getColor(R.color.bloodselect));
            textView9.setTextColor(getResources().getColor(R.color.heart));
            textView10.setTextColor(getResources().getColor(R.color.heart));
            textView11.setTextColor(getResources().getColor(R.color.heart));
            textView12.setTextColor(getResources().getColor(R.color.bloodselect));
            textView13.setTextColor(getResources().getColor(R.color.bloodselect));
            textView14.setTextColor(getResources().getColor(R.color.bloodselect));
            textView15.setTextColor(getResources().getColor(R.color.bloodselect));
            textView16.setTextColor(getResources().getColor(R.color.bloodselect));
            textView17.setTextColor(getResources().getColor(R.color.bloodselect));
            textView18.setTextColor(getResources().getColor(R.color.bloodselect));
            textView19.setTextColor(getResources().getColor(R.color.bloodselect));
            textView20.setTextColor(getResources().getColor(R.color.bloodselect));
            textView21.setTextColor(getResources().getColor(R.color.bloodselect));
            textView22.setTextColor(getResources().getColor(R.color.bloodselect));
            textView23.setTextColor(getResources().getColor(R.color.bloodselect));
            textView24.setTextColor(getResources().getColor(R.color.bloodselect));
            textView25.setTextColor(getResources().getColor(R.color.bloodselect));
        }
    }

    /**
     * 创建新检查清空数据
     */
    private void clearData() {
        xiongbu = false;
        youshangzhi = false;
        youxiazhi = false;
        toubu = false;
        jingbu = false;
        zuoshangzhi = false;
        fubu = false;
        zuoxiazhi = false;
        beibu = false;

        //胸部
        btnChest.setImageResource(R.mipmap.btn_chest);
        chestSelect.setVisibility(View.INVISIBLE);
        //右上肢
        btnRightUp.setImageResource(R.mipmap.youshangzhi_ok);
        rightupSelect.setVisibility(View.INVISIBLE);
        //右下肢
        btnRightLow.setImageResource(R.mipmap.btn_right_lower_limb);
        rightlowSelect.setVisibility(View.INVISIBLE);
        //头部
        btnHeadOk1.setImageResource(R.mipmap.btn_head_ok);
        headSelect.setVisibility(View.INVISIBLE);
        //颈部
        btnNeck1.setImageResource(R.mipmap.btn_neck);
        neckSelect.setVisibility(View.INVISIBLE);
        //左上肢
        btnLeftup.setImageResource(R.mipmap.btn_left_upper_limb);
        leftupSelect.setVisibility(View.INVISIBLE);
        //腹部
        btnAbdomen1.setImageResource(R.mipmap.btn_abdomen);
        fubuSelect.setVisibility(View.INVISIBLE);
        //左下肢
        btnLeftLow.setImageResource(R.mipmap.btn_left_lower_limb);
        leftlowSelect.setVisibility(View.INVISIBLE);
        //背部
        btnBack.setImageResource(R.mipmap.back_normal);

        eye = 0;
        yuyan = 0;
        yundong = 0;

        textView4.setText("");
        textView6.setText("");
        textView7.setText("");
        textView8.setText("");
        xuexing.setText("血型");
        xuexingStr = "血型";
        nameTv.setText("");
        idcardEt.setText("");
        editText2.setText("");
        textView14.setText("-");
        textView16.setText("-");
        textView19.setText("--");
        textView22.setText("--");
        textView25.setText("--");
        eyeRg.clearCheck();
        yuyanRg.clearCheck();
        yundongRg.clearCheck();
        eyeRb1.setText("不睁眼");
        eyeRb2.setText("刺痛睁眼");
        eyeRb3.setText("呼吸睁眼");
        eyeRb4.setText("自动睁眼");
        yuyanRb1.setText("不能言语");
        yuyanRb2.setText("只能发言");
        yuyanRb3.setText("答非所问");
        yuyanRb4.setText("回答不切题");
        yuyanRb5.setText("回答切题");
        yundongRb1.setText("不能活动");
        yundongRb2.setText("刺痛后肢体能过度伸展");
        yundongRb3.setText("刺痛后肢体能屈曲");
        yundongRb4.setText("刺痛后能躲避");
        yundongRb5.setText("刺痛能定位");
        yundongRb6.setText("按吩咐动作");
    }

    private SerialPortService mSerialPortService = SerialPortService.getInstance();
    private SerialPortService1 mSerialPortService1 = SerialPortService1.getInstance();
    private SerialPortService2 mSerialPortService2 = SerialPortService2.getInstance();
    private byte[] tempByte = new byte[0];

    /**
     * 串口初始化--温度
     */
    private void initSerialPort() {
        //串口打开状态的监听
        mSerialPortService.setOnOpenSerialPortListener(new OnOpenSerialPortListener() {
            @Override
            public void onSuccess(File file) {
                Log.d(TAG, "串口打开：onSuccess");
                Toast.makeText(getActivity(), "温度串口打开成功", Toast.LENGTH_SHORT).show();

            }

            // TODO: 2021/4/20  
            @Override
            public void onFail(File file, Status status) {
                Log.d(TAG, "串口打开：onFail");
                Toast.makeText(getActivity(), "温度串口打开失败", Toast.LENGTH_SHORT).show();

            }
        });

        //打开串口--温度
        mSerialPortService.openSerialPort(new File("/dev/ttyUSB1"), 9600);
        mSerialPortService.setOnSerialPortDataListener(new OnSerialPortDataListener() {
            @Override
            public void onDataReceived(byte[] bytes) {
                tempByte = ByteUtils.addBytes(tempByte, bytes);
                Log.e("温度数据: ", DataConvert.bytes2String(tempByte));
                if (tempByte.length == 21 && tempByte[0] == 1 && tempByte[1] == 3) {

                    //环境温度原始数据
//                    byte[] datahuajing = new byte[]{tempByte[5], tempByte[6]};

                    byte[] dataTemp = new byte[]{tempByte[3], tempByte[4]};
                    //工作温度数据
//                    double wenduhuanjing = ((double) getByte(datahuajing, 0)) / 100;
                    //原始数据
                    double wenduDouble = ((double) getByte(dataTemp, 0)) / 100;
                    Log.e("onDataReceived aaaaa: ", wenduDouble + "");

                    if (wenduDouble >= 28.00 && wenduDouble <= 40.00) {
                        //截取成28.1这种格式
                        String strSub = String.valueOf(wenduDouble).substring(0, 4);
                        //再转换为double类型  28.10
                        double temp = Double.parseDouble(strSub);
                        //获取截取前后的差值
                        double diff = wenduDouble - temp;
                        //去map里面查询,得到28.10对应的值
                        double temperature = TemAdd.temMap(temp);
                        //该值再加上差值进行还原
                        double result = temperature + diff;
                        Log.e("onDataReceived bbbbb: ", result + "" + "差值是：" + diff);

                        //四舍五入  保留一位小数
                        wendu = String.valueOf(new BigDecimal(result).setScale(1,
                                BigDecimal.ROUND_HALF_UP).doubleValue());
//                        wendu = String.valueOf(wenduDouble);

//                        wendu1 = String.valueOf(wenduhuanjing);
//                    Log.e(TAG, "onDataReceived: " + wendu);
                        Message message = new Message();
                        message.what = 0;
                        handler.sendMessage(message);
                    }
                    tempByte = new byte[0];
                }
            }

            @Override
            public void onDataSent(byte[] bytes) {
                Log.e(TAG, "onDataSent: " + DataConvert.bytes2String(bytes));
            }
        });
    }

    private int shousuoya;
    private int shuzhangya;
    private int xueyang;
    private int huxilv;
    private int xinlv;

    /**
     * 另一个串口 心电-血压-血氧-心率等数据
     */
    private void initSerialPort1(String path) {
        //打开监听
        mSerialPortService1.setOnOpenSerialPortListener(new OnOpenSerialPortListener1() {
            @Override
            public void onSuccess(File var1) {
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                mSerialPortService1.sendBytes(MakePackage.makeBytes3());//心电
                mSerialPortService1.sendBytes(MakePackage.makeBytes2());//血压
                mSerialPortService1.sendBytes(MakePackage.makeBytes4());//心电波形
            }

            @Override
            public void onFail(File var1, OnOpenSerialPortListener.Status var2) {
                Log.e(TAG, "initSerialPort1-onFail: " + var2);
            }
        });

        mSerialPortService1.openSerialPort(new File("/dev/ttyMSM3"), 115200);

        mSerialPortService1.setOnSerialPortDataListener(new OnSerialPortDataListener1() {
            @Override
            public void onDataReceived(byte[] var1) {
                String data = DataConvert.bytes2String(var1);

                //血压
                if (data.startsWith("55aa") && data.length() > 16) {
                    if (var1[3] == 3 && var1[4] == 0) {
                        shousuoya = 0xff & var1[6];
                        shuzhangya = 0xff & var1[8];
//                        Log.e(TAG, "收缩压：" + (0xff & var1[6]) + "舒张压：" + (0xff & var1[8]));
                        Message message = new Message();
                        message.what = 1;
                        handler.sendMessage(message);
                    }
                }

                //血氧
                if (data.startsWith("55aa") && data.length() >= 16) {
                    if (var1[3] == 4 && var1[4] == 0) {
                        xueyang = 0xff & var1[5];
//                        Log.e(TAG, data);
                        Message message = new Message();
                        message.what = 2;
                        handler.sendMessage(message);
                    }
                }
                //心电
                if (data.startsWith("55aa") && data.length() >= 20) {
                    if (var1[3] == 2) {
//                        Log.e("onDataReceived: ", data);
                        huxilv = 0xff & var1[6];
                        xinlv = 0xff & var1[5];
                        Message message = new Message();
                        message.what = 3;//呼吸率
                        handler.sendMessage(message);
                    }
                }

                //心电波形
                if (data.startsWith("55aa") && data.length() >= 12) {
                    if (var1[3] == 1) {
//                        Log.e("onDataReceived: ", data);

//                        if (heartData.size() >= 2500) {
//
//                        }
//                        heartData.add(DataConvert.convertByteToInt(var1[4]));
                        if (mIntegerCopyOnWriteArrayList.size() >= 2500) {
                            mIntegerCopyOnWriteArrayList.remove(0);
                        }
                        mIntegerCopyOnWriteArrayList.add(DataConvert.convertByteToInt(var1[4]));

                        if (i == 250) {
                            i = 0;
                            Message messag = new Message();
                            messag.what = 4;
//                            handler.sendMessage(messag);
                        }
                        mBytes[i] = 0xff & var1[4];
                        i++;
                    }
                }
            }

            @Override
            public void onDataSent(byte[] var1) {
                Log.e(TAG, "onDataSent: " + DataConvert.bytes2String(var1));
            }
        });
    }

    private boolean isRead = true;

    private byte[] tempByteId = new byte[]{};
    String[] decodeInfo = new String[10];

    /**
     * 身份证读取串口
     */
    private void initSerialPort2() {
        //串口打开状态的监听
        mSerialPortService2.setOnOpenSerialPortListener(new OnOpenSerialPortListener2() {
            @Override
            public void onSuccess(File file) {
                Log.d(TAG, "串口打开：onSuccess");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        while (true) {
                            if (isRead) {
                                mSerialPortService2.sendBytes(MakePackage.cmd_find);
                                try {
                                    Thread.sleep(200);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            }
                        }
                    }
                }).start();
            }

            @Override
            public void onFail(File var1, OnOpenSerialPortListener.Status var2) {

            }
        });

        //打开串口--身份证
        mSerialPortService2.openSerialPort(new File("/dev/ttyMSM2"), 115200);
        mSerialPortService2.setOnSerialPortDataListener(new OnSerialPortDataListener2() {
            @Override
            public void onDataReceived(byte[] bytes) {
//                Log.e("身份证数据: ", DataConvert.bytes2String(bytes));
                String strIDCard = DataConvert.bytes2String(bytes);
                if (strIDCard.equals("aaaaaa9669000400008084")) {
                } else if (strIDCard.equals("aaaaaa9669000800009f0000000097")) {
                    mSerialPortService2.sendBytes(MakePackage.cmd_selt);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else if (strIDCard.equals("aaaaaa9669000c00009000000000000000009c")) {
                    mSerialPortService2.sendBytes(MakePackage.cmd_read);
                } else if (strIDCard.equals("aaaaaa9669000400004145")) {
                    tempByteId = new byte[]{};
                } else {
                    tempByteId = ByteUtils.addBytes(tempByteId, bytes);
                    if (tempByteId.length >= 1295) {
                        if (tempByteId[0] == -86 && tempByteId[1] == -86 && tempByteId[2] == -86) {
                            Log.e(TAG, "身份证数据读取完毕");
                            byte[] dataBuf = new byte[256];
                            for (int i = 0; i < 256; i++) {
                                dataBuf[i] = tempByteId[14 + i];
                            }
                            String TmpStr = null;
                            try {
                                TmpStr = new String(dataBuf, "UTF16-LE");
                                TmpStr = new String(TmpStr.getBytes("UTF-8"));
                                decodeInfo[0] = TmpStr.substring(0, 15);
                                decodeInfo[1] = TmpStr.substring(15, 16);
                                decodeInfo[2] = TmpStr.substring(16, 18);
                                decodeInfo[3] = TmpStr.substring(18, 26);
                                decodeInfo[4] = TmpStr.substring(26, 61);
                                decodeInfo[5] = TmpStr.substring(61, 79);
                                decodeInfo[6] = TmpStr.substring(79, 94);
                                decodeInfo[7] = TmpStr.substring(94, 102);
                                decodeInfo[8] = TmpStr.substring(102, 110);
                                decodeInfo[9] = TmpStr.substring(110, 128);
                                Log.e(TAG, "号码" + decodeInfo[5]);
                                idNum = decodeInfo[5];
                                Message message = new Message();
                                message.what = 12;
                                handler.sendMessage(message);

                            } catch (UnsupportedEncodingException e) {
                                e.printStackTrace();
                            }
                            tempByteId = new byte[]{};
                        } else {
                            tempByteId = new byte[]{};
                        }

                    }
                }
            }

            @Override
            public void onDataSent(byte[] bytes) {
//                Log.e(TAG, "onDataSent: " + DataConvert.bytes2String(bytes));
            }
        });
    }


    private CopyOnWriteArrayList<Integer> mIntegerCopyOnWriteArrayList = new CopyOnWriteArrayList<>();

    private int[] mBytes = new int[250];//心电图数据
    int i = 0;
    private int mECGX = -1, mECGY;

    public static int getByte(byte[] src, int offset) {
        int value = (src[offset] & 255) << 8 | (src[offset + 1] & 255) << 0;
        return value;
    }

    //byte
    public static int getByte1(byte src, int position) {
        int value = (src & (0x01 << position));//01 02 04 08 10 20 40 80
        return value;
    }

    private class ImageTask extends AsyncTask<String, Integer, Bitmap> {
        @Override
        protected Bitmap doInBackground(String... params) {
            return creatImage();
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
//            imageBtn.setText("正在生成 - 请等待 不要着急");

        }

        @Override
        protected void onPostExecute(Bitmap bitmap) {
            super.onPostExecute(bitmap);
//            imageBtn.setText("生成");
//            mView.setImageBitmap(bitmap);

            String str = "";
            try {
                if (TextUtils.isEmpty(nameTv.getText().toString())) {
//                    Toast.makeText(getContext(), "请先补充检伤信息！", Toast.LENGTH_SHORT).show();
                    mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请先补充检伤信息！");
                    mNormalDialog.show();
                    mNormalDialog.getWindow().setLayout(1000, 500);
                    str = "--";
                } else {
                    str = nameTv.getText().toString();
                }
                FileUtils.saveFile(bitmap, DateUtils.stampToDate(new Date().getTime()) + "_" + str + ".jpeg", "");
            } catch (IOException e) {
                e.printStackTrace();
            }

            exportDataDialog.setMessage("导出成功！");
            exportDataDialog.setCanceledOnTouchOutside(true);
        }
    }

    private Bitmap creatImage() {
//        try {
//        InputStream ins = getContext().getAssets().open("res" + File.separator + "print.bmp");
//            Bitmap imageBitmap = BitmapFactory.decodeStream(ins);
        ArrayList<StringBitmapParameter> headParams = new ArrayList<>();
        headParams.add(new StringBitmapParameter("时间：" + DateUtils.stampToDate(new Date().getTime())));
        headParams.add(new StringBitmapParameter("\n"));

        headParams.add(new StringBitmapParameter("姓名：" + nameTv.getText().toString()
                + "\u3000编号：" + editText2.getText().toString().replace(" ", "")
                + "\u3000血型：" + xuexingStr));

        ArrayList<StringBitmapParameter> mParameters = new ArrayList<>();

        mParameters.add(new StringBitmapParameter("\n"));
        mParameters.add(new StringBitmapParameter("\n"));
        mParameters.add(new StringBitmapParameter("\u3000心率：" + textView11.getText().toString() + "bpm"));
        mParameters.add(new StringBitmapParameter("呼吸率：" + textView22.getText().toString() + "RR"));
        mParameters.add(new StringBitmapParameter("收缩压：" + textView14.getText().toString() + "mmHg"));
        mParameters.add(new StringBitmapParameter("舒张压：" + textView16.getText().toString() + "mmHg"));
        mParameters.add(new StringBitmapParameter("\u3000血氧：" + textView19.getText().toString() + "%"));
        mParameters.add(new StringBitmapParameter("\u3000体温：" + textView25.getText().toString() + "℃"));
        mParameters.add(new StringBitmapParameter("\n"));
        String eyeStr = "";
        switch (eye) {
            case 1:
                eyeStr = "不睁眼";
                break;
            case 2:
                eyeStr = "刺痛睁眼";
                break;
            case 3:
                eyeStr = "呼吸睁眼";
                break;
            case 4:
                eyeStr = "自动睁眼";
                break;
        }
        mParameters.add(new StringBitmapParameter("睁眼动作：" + eyeStr));

        String yuyanStr = "";
        switch (yuyan) {
            case 1:
                yuyanStr = "不能言语";
                break;
            case 2:
                yuyanStr = "只能发言";
                break;
            case 3:
                yuyanStr = "答非所问";
                break;
            case 4:
                yuyanStr = "回答不切题";
                break;
            case 5:
                yuyanStr = "回答切题";
                break;
        }
        mParameters.add(new StringBitmapParameter("语言反应：" + yuyanStr));

        String yundongStr = "";
        switch (yundong) {
            case 1:
                yundongStr = "不能活动";
                break;
            case 2:
                yundongStr = "刺痛后肢体能过度伸展";
                break;
            case 3:
                yundongStr = "刺痛后肢体能屈曲";
                break;
            case 4:
                yundongStr = "刺痛后能躲避";
                break;
            case 5:
                yundongStr = "刺痛能定位";
                break;
            case 6:
                yundongStr = "按吩咐动作";
                break;
        }
        mParameters.add(new StringBitmapParameter("运动反应：" + yundongStr));
        mParameters.add(new StringBitmapParameter("\n"));
        mParameters.add(new StringBitmapParameter("\n"));

        mParameters.add(new StringBitmapParameter("评分：" + textView4.getText().toString() + "分 " + textView8.getText().toString() + " " + textView7.getText().toString()));


        ArrayList<StringBitmapParameter> mParametersEx = new ArrayList<>();/**如果是空的列表，也可以传入，会打印空行*/
        mParametersEx.add(new StringBitmapParameter("\n"));

        Bitmap textBitmap = ImgUtils.StringListtoBitmap(getContext(), mParameters);
//            Bitmap textBitmap2 = ImgUtils.StringListtoBitmap(getContext(), mParametersEx);
        Bitmap headBitmap = ImgUtils.StringListtoBitmapLarge(getContext(), headParams);

//            Bitmap mergeBitmap = ImgUtils.addBitmapInHead(imageBitmap, textBitmap);
//            Bitmap mergeBitmap2 = ImgUtils.addBitmapInFoot(mergeBitmap, imageBitmap);
//            Bitmap mergeBitmap3 = ImgUtils.addBitmapInFoot(mergeBitmap2, textBitmap2);
        Bitmap mergeBitmap4 = ImgUtils.addBitmapRight(textBitmap, ImgUtils.captureView(bodyFl));
        Bitmap bitmap5 = ImgUtils.addBitmapInHead(headBitmap, mergeBitmap4);
//            Log.e("fmx", "argb_8888 =  " + mergeBitmap3.getHeight() * mergeBitmap3.getWidth() * 32);
//            Log.e("fmx", "rgb_565 =  " + mergeBitmap3.getHeight() * mergeBitmap3.getWidth() * 16);
        return bitmap5;
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return null;
    }

    private void createData() {
        DataBean dataBean = new DataBean();
        Date date = new Date();
        dataBean.setNumber(editText2.getText().toString());
        dataBean.setName(nameTv.getText().toString());
        int shousuoyaLevel = 0;

        if (!textView14.getText().toString().equals("-")) {
            if (Integer.parseInt(textView14.getText().toString()) > 89) {
                shousuoyaLevel = 4;
            } else if (Integer.parseInt(textView14.getText().toString()) <= 89 && Integer.parseInt(textView14.getText().toString()) >= 76) {
                shousuoyaLevel = 3;
            } else if (Integer.parseInt(textView14.getText().toString()) <= 75 && Integer.parseInt(textView14.getText().toString()) >= 50) {
                shousuoyaLevel = 2;
            } else if (Integer.parseInt(textView14.getText().toString()) >= 1 && Integer.parseInt(textView14.getText().toString()) <= 49) {
                shousuoyaLevel = 1;
            }
        } else {
//            Toast.makeText(getContext(), "请测量血压", Toast.LENGTH_LONG).show();
            mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量血压！");
            mNormalDialog.show();
            mNormalDialog.getWindow().setLayout(1000, 500);
            return;
        }

        int huxilv = 0;
        if (!textView22.getText().toString().equals("--")) {
            if (Integer.parseInt(textView22.getText().toString()) > 29) {
                huxilv = 3;
            } else if (Integer.parseInt(textView22.getText().toString()) >= 10 && Integer.parseInt(textView22.getText().toString()) <= 29) {
                huxilv = 4;
            } else if (Integer.parseInt(textView22.getText().toString()) >= 6 && Integer.parseInt(textView22.getText().toString()) <= 9) {
                huxilv = 2;
            } else if (Integer.parseInt(textView22.getText().toString()) >= 4 && Integer.parseInt(textView22.getText().toString()) <= 5) {
                huxilv = 1;
            }
        } else {
//            Toast.makeText(getContext(), "请测量呼吸率", Toast.LENGTH_LONG).show();
            mNormalDialog = new NormalDialog(getContext(), R.style.TipDialog, "请测量呼吸率！");
            mNormalDialog.show();
            mNormalDialog.getWindow().setLayout(1000, 500);
        }
        int shenzhipanduan = 0;
        int shenzhi = eye + yuyan + yundong;
        if (shenzhi >= 13 && shenzhi <= 15) {
            shenzhipanduan = 4;
        } else if (shenzhi >= 9 && shenzhi <= 12) {
            shenzhipanduan = 3;
        } else if (shenzhi >= 6 && shenzhi <= 8) {
            shenzhipanduan = 2;
        } else if (shenzhi >= 4 && shenzhi <= 5) {
            shenzhipanduan = 1;
        }

        int shangqingLevel = shenzhipanduan + huxilv + shousuoyaLevel;

        dataBean.setScore(shangqingLevel);
        dataBean.setEye(eye);
        dataBean.setSay(yuyan);
        dataBean.setSport(yundong);
        dataBean.setCreateTime(date);
    }

    private void getFile() {
        RootCmd.execRootCmdSilent("su");
        StringBuilder sb = new StringBuilder("");

        //打开文件输入流
        FileInputStream inputStream = null;
        try {
            inputStream = new FileInputStream("/proc/tty/driver/usbserial");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

        byte[] buffer = new byte[1024];
        int len = 0;
        try {
            len = inputStream.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        //读取文件内容
        while (len > 0) {
            sb.append(new String(buffer, 0, len));

            //继续将数据放到buffer中
            try {
                len = inputStream.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        Log.e(TAG, "getFile: " + sb);
        //关闭输入流
        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private String getInfo() {
        CmdExample cmd = new CmdExample(false).run("cat /proc/tty/driver/usbserial", 60000);
        while (cmd.isRunning()) {
            Log.d(TAG, "getInfo: runningman");
            try {
                sleep(1000);
            } catch (Exception e) {
            }
        }

        String buf = cmd.getResult();
        int pos = buf.indexOf(": name:\"cp210x\" vendor:10c4 product:ea60 num_ports:1 port:0 path:usb-0000:00:14.0-4.4.2");
        Log.e(TAG, "getInfo: " + buf);
//        Log.e(TAG, "getInfo: =====" + buf.substring(pos - 1, pos));

        cmd.onDestroy();
        return buf.substring(pos - 1, pos);
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        Log.e(TAG, "onAttach: ");
//        initSerialPort1("/dev/ttyUSB" + getInfo());
    }

    @Subscribe(threadMode = ThreadMode.BACKGROUND)
    public void openSerialPort(InvokPortBean invokPortBean) {
        if (invokPortBean.isPower()) {
            Message message = new Message();
            message.what = 10;
            handler.sendMessage(message);

//            try {
//                initSerialPort();
//                Thread.sleep(5000);
//                initSerialPort1("/dev/ttyUSB" + getInfo());
            Message message1 = new Message();
            message1.what = 11;
            handler.sendMessage(message1);
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
        } else {
            if (mInitPortDialog != null) {
                mInitPortDialog.dismiss();
            }
//            if (mSerialPortService != null) {
//                mSerialPortService.closeSerialPort();
//            }
            if (mSerialPortService1 != null) {
                mSerialPortService1.closeSerialPort();
            }
        }
    }

    /**
     * 海南的
     * @param postBean
     */
    private void upload(PostBean postBean) {
//        ApiWrapper.getInstance().post(postBean)
//                .compose(RxHelper.to_mian())
//                .subscribe(new MyObserver<PostResponse>() {
//                    @Override
//                    public void onError(ExceptionHandle.ResponseException responseException) {
//                        Log.e(TAG, "onError: " + responseException.getMessage());
//                    }
//
//                    @Override
//                    public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {
//
//                    }
//
//                    @Override
//                    public void onNext(@io.reactivex.annotations.NonNull PostResponse postResponse) {
//                        Log.e(TAG, "onNext: " + postResponse.getMsg() + postResponse.getCode());
//                    }
//
//                    @Override
//                    public void onComplete() {
//
//                    }
//                });
    }

    /**
     * 湛江的
     * @param postben2
     */
    private void upload2(PostBean2 postben2) {

        ApiWrapper.getInstance().post2(postben2)
                .compose(RxHelper.to_mian())
                .subscribe(new MyObserver<PostReceive2>() {
                    @Override
                    public void onError(ExceptionHandle.ResponseException responseException) {
                        Log.e(TAG, "onError: " + responseException.getMessage());
                    }

                    @Override
                    public void onSubscribe(@io.reactivex.annotations.NonNull Disposable d) {

                    }

                    @Override
                    public void onNext(@io.reactivex.annotations.NonNull PostReceive2 postReceive2) {
                        Log.e(TAG, "onNext: ");
                    }

                    @Override
                    public void onComplete() {

                    }
                });

    }


}